Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(select): Fix all syncing issues with the Select component #2983

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update upgrade guide
NicholasBoll committed Oct 14, 2024
commit 192a7c15da58fd5dab320f83677c45b4c29982e5
30 changes: 29 additions & 1 deletion modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
Original file line number Diff line number Diff line change
@@ -281,6 +281,34 @@ component composing them.
</Combobox>

// Better - create a specialized component
NicholasBoll marked this conversation as resolved.
Show resolved Hide resolved
const useMyComboboxInput = composeHooks(
// or your own model that extends `useComboboxModel`
createElemPropsHook(useComboboxModel)(model => {
return {
// anything you need your input to do
}
}),
useComboboxInputArbitrary,
useComboboxInput
)

const MyComboboxInput = createSubcomponent(TextInput)({
// or your own model that extends `useComboboxModel`
modelHook: useComboboxModel,
elemPropsHook: useMyComboboxInput,
})((elemProps, Element) => {
// return a TextInput
return <Element {...elemProps} />

// return an InputGroupgs
return (
<InputGroup>
<InputGroup.InnerStart>{/* Icon or something */}</InputGroup.InnerStart>
<InputGroup.Input as={Element} {...elemProps} />
<InputGroup.InnerEnd><InputGroup.ClearButton /></InputGroup.InnerEnd>
</InputGroup>
)
})
```

### Form Field
@@ -537,7 +565,7 @@ const theme: PartialEmotionCanvasTheme = {
```

`Select` has been refactored to use `useComboboxInputConstrained` to sync the model and the `input`
element regardless of the source. This makes the `Select` be a controllable component.
element regardless of the source. This makes the `Select` a controllable component.

### Text Area

15 changes: 8 additions & 7 deletions modules/react/combobox/stories/Combobox.mdx
Original file line number Diff line number Diff line change
@@ -30,13 +30,14 @@ pick from these values, but cannot input a value outside the options provided. C
comboboxes use the [useComboboxInputConstrained](#usecomboboxinputconstrained) hook and often have
two separate `input` elements.

- user input - This is the visible input. It should contain user-friend values. Calls to `.focus()`
or `.blur()` are redirected to this input. Any prop passed to the `*.Input` component that is not
directly related to forms will be passed here (i.e. `data-testid`, `aria-*`, etc).
- form input - This input is only visible to forms. The `value` will usually be server IDs. If the
combobox options don't have an ID and only use user values, the value of this input will be the
same as the user input. Any prop related to the function of forms will be passed here. For
exampple, the `name` attribute will be passed here. The `ref` will pointed to this element.
- user input - This is the visible input and it should contain user-friendly values. Calls to
`.focus()` or `.blur()` are redirected to this input. Any prop passed to the `*.Input` component
that is not directly related to forms will be passed here (i.e. `data-testid`, `aria-*`, etc).

- form input - This input is only visible to forms and the `value` will usually be server IDs. If
the combobox options don't have an ID and only use user values, the value of this input will be
the same as the user input. Any prop related to the function of forms will be passed here. For
example, the `name` attribute will be passed here. The `ref` will be pointed to this element.

### Arbitrary