Comments (1)
I ended up creating my own checkbox by copying this repo and modifying it to fit my needs.
One of the issues I had was with including useMergedState
in my module.... this seems to be an export issue with the rc-util
package not being developed for ESM.
My solution was to get rid of useMergedState
entirely. The alternative was actually quite simple - useEffect
and useState
combined: -
const [isChecked, setIsChecked] = useState<boolean>(false)
useEffect(() => {
setIsChecked(checked || defaultChecked || false)
}, [setIsChecked, checked, defaultChecked])
const handleChange = (e: ChangeEvent<HTMLInputElement>): void => {
if (disabled) return
setIsChecked(!isChecked)
[...]
}
Then I can just use the state isChecked
as normal (where rawValue
would have been used).
I created a test harness of all possibilities and it passed: -
const arr = [
{ checked: undefined, defaultChecked: undefined, expected: false },
{ checked: undefined, defaultChecked: false, expected: false },
{ checked: undefined, defaultChecked: true, expected: true },
{ checked: false, defaultChecked: undefined, expected: false },
{ checked: false, defaultChecked: false, expected: false },
{ checked: false, defaultChecked: true, expected: true },
{ checked: true, defaultChecked: undefined, expected: true },
{ checked: true, defaultChecked: false, expected: true },
{ checked: true, defaultChecked: true, expected: true }
]
All elements displayed and behaved as expected.
Although I am considering moving the defaultChecked
option to force this to be a controlled component (personal preference).
from checkbox.
Related Issues (20)
- Prop "title" is ignored HOT 4
- Unusable typescript typing
- d.ts 更新能发版本不? HOT 1
- Support 'required' attribute, as it currently can't be passed onto the input
- Component doesn't work with React ref
- Bug: 2.2.0 移除了 react-lifecycles-compat 导致在 react 15 下 value 不受控
- Version 2.3 does not have Typescript types included
- BUG:Key events on checkbox HOT 1
- Checkbox Event Type Error HOT 1
- Change the color? HOT 2
- Migrate docs to dumi
- Bug: Defaulted props not used in onChange callback HOT 2
- [feature]: need an event object in onChange handler
- Wrong proptype for tabIndex HOT 1
- Error with React 16.3.2 HOT 2
- expose `currentTarget` in `handleChange`
- Invalid prop `checked` supplied to `Checkbox` HOT 3
- print doesn't show checked values
- componentWillReceiveProps is deprecated and will be removed in the next major version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from checkbox.