Skip to content

Commit 11e0542

Browse files
committed
docs(:memo:) updating docs
- Using correct search key - Adding info on using `checked` - Adding gotchas for indeterminates
1 parent f04efb2 commit 11e0542

File tree

5 files changed

+705
-541
lines changed

5 files changed

+705
-541
lines changed

docs/docs/checkbox.md

+29
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,32 @@ Controlled indeterminates have a whole host of usages including trees!
256256
return App;
257257
})()
258258
```
259+
260+
### `indeterminate` Gotchas
261+
262+
No pun intended :laughing:. Okay, but seriously there's one gotcha regarding `indeterminate` prop usage you need to be aware of. In rare cases usage of the `indeterminate` prop with `checked` will result in the checkbox becoming immediately checked after React re-renders the component. Be sure `indeterminate` is `undefined`:
263+
264+
```jsx {3}
265+
<Checkbox
266+
checked={checked}
267+
indeterminate={indeterminate || undefined}
268+
onChange={/* ... */}
269+
icon={/* ... */} />
270+
```
271+
272+
This is due to a side effect in `useIndeterminate.ts` and in particular the three highlighted lines below:
273+
274+
```js {3,5,7}
275+
React.useEffect(() => {
276+
if (
277+
state !== 'indeterminate' &&
278+
ref.current &&
279+
typeof indeterminateFromProps !== 'undefined'
280+
) {
281+
ref.current.checked = indeterminateFromProps;
282+
setStatus(indeterminateFromProps);
283+
}
284+
}, [indeterminateFromProps, state]);
285+
```
286+
287+
If `indeterminateFromProps` is `false` (not `undefined`) then our checkbox becomes immediately unchecked :cry:.

docs/docs/main-concepts/controlled.md

+20
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,23 @@ class App extends React.Component {
156156
}
157157
}
158158
```
159+
160+
### Using `checked`
161+
162+
For ultra fine-grained control you can use the `checked` prop to _completely_ control the input:
163+
164+
```jsx live
165+
function App() {
166+
const [checked, setChecked] = React.useState(false);
167+
168+
const onChange = React.useCallback(() => {
169+
setChecked(prev => !prev);
170+
}, []);
171+
172+
return (
173+
<Checkbox checked={checked} onChange={onChange}>
174+
Checked: {checked + ''}
175+
</Checkbox>
176+
);
177+
}
178+
```

docs/docusaurus.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module.exports = {
143143
},
144144
algolia: {
145145
apiKey: process.env.ALGOLIA_KEY,
146-
indexName: 'pretty-checkbox',
146+
indexName: 'pretty-checkbox-react',
147147
searchParameters: {}, // Optional (if provided by Algolia)
148148
},
149149
},

docs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
},
3939
"devDependencies": {
4040
"@djthoms/docusaurus-plugin-sass": "^0.2.0",
41-
"@docusaurus/module-type-aliases": "^2.0.0-alpha.64",
42-
"docusaurus-plugin-module-alias": "^0.0.1",
41+
"@docusaurus/module-type-aliases": "^2.0.0-alpha.68",
42+
"docusaurus-plugin-module-alias": "^0.0.2",
4343
"docusaurus-plugin-react-docgen-typescript": "^0.0.1",
4444
"react-docgen-typescript": "^1.20.4",
4545
"sass": "^1.26.10",

0 commit comments

Comments
 (0)