component-driven / ui Goto Github PK
View Code? Open in Web Editor NEWA collection of packages for common UI problems
Home Page: https://ui.component-driven.dev
License: MIT License
A collection of packages for common UI problems
Home Page: https://ui.component-driven.dev
License: MIT License
I discovered a strange behavior in the FocusWithin
component when I was building a custom input component. When I clicked outside of the wrapper element of the custom inputs, the lastly activated input kept the focus style.
After that, I tried one of the examples from the documentation in a newly created react app and the FocusWithin
component behaved the exact same that I experienced earlier.
Reproduction steps:
create-react-app
command.App.js
file (you can find it at the bottom of the issue).form
element.Current result: If you click outside of the form
horizontally, it works fine, because the area is in the wrapper element of the form, but if you click outside vertically, that space is out of the wrapper component, so the form
will keep the focused state.
Expected result: The form
should lose the focus that when the user clicks outside of it.
import React from 'react';
import { FocusWithin } from '@component-driven/react-focus-within';
function App() {
return (
<div className="App">
<FocusWithin
onFocus={() => {
console.log('Received focus')
}}
onBlur={() => {
console.log('Lost focus')
}}
>
{({ focused, getRef }) => (
<form style={{ margin: '100px auto', width: '300px' }}>
<fieldset
ref={getRef}
style={{ borderColor: focused ? 'blue' : '#999' }}
>
<div>
<label htmlFor="input1">First input</label>
<input
id="input1"
type="text"
placeholder="Click to activate first input"
/>
</div>
<div>
<label htmlFor="input2">First input</label>
<input
id="input2"
type="text"
placeholder="Use Tab to activate next input"
/>
</div>
<button type="submit">Submit</button>
<p style={{ color: focused ? 'danger' : 'text' }}>
{focused ? 'Focus is inside' : 'No focus here'}
</p>
</fieldset>
</form>
)}
</FocusWithin>
</div>
);
}
export default App;
The way vanilla-extract handles selectors is a bit different from other CSS-in-JS solutions and it fails to work with the library now. In order to make it work with it, we need to switch to matching the pseudo-selector in the document.styleSheets
and then narrow it down to the element somehow.
import { FocusWithin } from @component-driven/react-focus-within
import { FocusWithin } from "@component-driven/react-focus-within"
Hey Andrey, I love this component!
I was wondering if there is any specific reason why children
is a function. IMHO the state could be lifted up since anyway we get to register onFocus
and onBlur
. A minimal API like this https://codesandbox.io/s/vq5vzmxxrl would work as a baseline to build more complex ones.
FWIW it is probably better to avoid preventDefault/stopPropagation
since other components (ancestors) might rely on those events.
Maybe instead of generating a hash, we could use a replace
to replace invalid chars:
const generatedClassName = selector.replace(':', '-')
Currently, if a user has className
prop on the component, it will be overwritten.
Even better solution would be to go away from implicit cloneElement
under the hood and expose the hook or render props.
If the ref
wasn't passed to the component (for example, it doesn't implement React.forwardRef
), when it fails in runtime with
Cannot read properties of null (reading 'classList')
Currently, the component does cloneChildren
which is a very implicit and can lead to bugs like #58. It would be easier to implement it as a hook and let folks assign props to their components themselves.
master
branch failed. π¨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iβm sure you can resolve this πͺ.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those donβt help, or if this issue is reporting something you think isnβt right, you can always ask the humans behind semantic-release.
An npm token must be created and set in the NPM_TOKEN
environment variable on your CI environment.
Please make sure to create an npm token and to set it in the NPM_TOKEN
environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/
.
Good luck with your project β¨
Your semantic-release bot π¦π
The two values transparent
and currentColor
are valid css color values and therefore, the SmartWatch
component should not fail with a runtime error trying to parse them.
example code:
const calculatedTheme = {
...theme,
colors: {
...theme.colors,
transparent: 'transparent',
current: 'currentColor',
},
}
return <ThemeColors theme={calculatedTheme} />
without those two values, it works fine
Subj
If the container node got unmounted when the check
will lead to a TypeError Cannot read property 'contains' of null
Now the internal implementation is something different. Maybe we should change the name too.
Only with hex
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.