-
Notifications
You must be signed in to change notification settings - Fork 16
Combobox #2267
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
Merged
Merged
Combobox #2267
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
60b0cf6
Putting in example code to see how it works
charliepark 24b734a
Merge branch 'main' into stub_of_new_combobox
charliepark 44fd9a6
Continued development; styling
charliepark 857a8c2
Extracted Combobox
charliepark ff1818a
Shift from useState to form control
charliepark af7262b
CSS mostly working, though some redundancies
charliepark 9b0f08e
Remove existing dropdown
charliepark 22ce73b
Add no-match option, update mock API limit
charliepark 4944b4c
add placeholder
charliepark 22aec5f
Update pagination test to use Snapshots
charliepark b5043e2
Update tests
charliepark 201ab6a
Add ErrorMessage
charliepark 55a8f83
Merge branch 'main' into stub_of_new_combobox
david-crespo cbc55bd
share props type more directly between Combobox and ComboboxField
david-crespo 8d9a7db
increase gap
david-crespo 3249dcc
fix double border on options
david-crespo 032c891
don't match on value, only on label (visible text)
david-crespo ef8ce80
fix clearing field behavior, use matchSorter to get fuzzy matching
david-crespo 64a2598
use data attr instead of render prop for open
david-crespo 37c4978
cut a line out of the diff
david-crespo 63c4389
clean up listbox option too
david-crespo f22a958
Merge branch 'main' into stub_of_new_combobox
charliepark e1a7030
Add Combobox to disk tab in instance create form
charliepark dfa3648
Add max-width container to ComboboxField directly
charliepark 372d8f2
Smarter zIndex; also migrate IP Pool page to Combobox
charliepark f1f546f
Migrate SiloIpPoolsTab to Combobox
charliepark 39b1011
Cleanup unnecessary field modifications
charliepark 312193d
more cleanup
charliepark 33fffa0
Remove extra line from diff
charliepark 644c4ba
Change remaining 'simple' ListboxFields to ComboboxFields
charliepark e04a183
Remove prop accidentally included in last commit
charliepark 3b36d25
Update test with combobox
charliepark 341505c
not yet handling differing labels and values
charliepark 37f2a21
Test fixes
charliepark 2041764
Remove unneeded comment change
charliepark 789b92b
Merge branch 'main' into stub_of_new_combobox
charliepark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| import { | ||
| useController, | ||
| type Control, | ||
| type FieldPath, | ||
| type FieldValues, | ||
| } from 'react-hook-form' | ||
|
|
||
| import { Combobox, type ComboboxBaseProps } from '~/ui/lib/Combobox' | ||
| import { capitalize } from '~/util/str' | ||
|
|
||
| import { ErrorMessage } from './ErrorMessage' | ||
|
|
||
| export type ComboboxFieldProps< | ||
| TFieldValues extends FieldValues, | ||
| TName extends FieldPath<TFieldValues>, | ||
| > = { | ||
| name: TName | ||
| control: Control<TFieldValues> | ||
| onChange?: (value: string | null | undefined) => void | ||
| disabled?: boolean | ||
| } & ComboboxBaseProps | ||
|
|
||
| export function ComboboxField< | ||
| TFieldValues extends FieldValues, | ||
| TName extends FieldPath<TFieldValues>, | ||
| // TODO: constrain TValue to extend string | ||
| >({ | ||
| control, | ||
| name, | ||
| label = capitalize(name), | ||
| required, | ||
| onChange, | ||
| disabled, | ||
| ...props | ||
| }: ComboboxFieldProps<TFieldValues, TName>) { | ||
| const { field, fieldState } = useController({ name, control, rules: { required } }) | ||
| return ( | ||
| <div className="max-w-lg"> | ||
| <Combobox | ||
| isDisabled={disabled} | ||
| label={label} | ||
| required={required} | ||
| selected={field.value || null} | ||
| hasError={fieldState.error !== undefined} | ||
| onChange={(value) => { | ||
| field.onChange(value) | ||
| onChange?.(value) | ||
| }} | ||
| {...props} | ||
| /> | ||
| <ErrorMessage error={fieldState.error} label={label} /> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.