-
Notifications
You must be signed in to change notification settings - Fork 31
feat(SelectDropdown): isCreateable support, removes SearchIcon, styling fixes
#3371
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
Open
dreamwasp
wants to merge
38
commits into
main
Choose a base branch
from
cass-gmt-292
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
c8563bf
feat(SelectDropdown):isCreatable
dreamwasp 8d86bc8
tweaks
dreamwasp cabad9d
refactor prop table
dreamwasp 2ab39ce
write SelectDropdown skill
dreamwasp cd2dc5a
Merge branch 'main' into cass-gmt-292
dreamwasp 878a06f
tweak props + co-pilot
dreamwasp d99285b
Merge branch 'main' into cass-gmt-292
dreamwasp f2e6db1
as
dreamwasp 7064061
tweak
dreamwasp a4b27b8
SelectDropdown skill
dreamwasp 9000ba8
Merge branch 'main' into cass-gmt-292
dreamwasp c8f2d09
update skills
dreamwasp 5252f6a
refactor skills + stories
dreamwasp 5d1cbda
Merge branch 'main' into cass-gmt-292
dreamwasp cf1756a
Merge branch 'main' into cass-gmt-292
dreamwasp 82628dd
Merge branch 'cass-gmt-292' of github.com:Codecademy/gamut into cass-…
dreamwasp 20f8b22
amy edits
dreamwasp 53e75eb
Merge branch 'main' into cass-gmt-292
dreamwasp fc9bead
change placeholde text color
dreamwasp 721362e
Merge branch 'cass-gmt-292' of github.com:Codecademy/gamut into cass-…
dreamwasp 7c6722a
Update packages/gamut/src/Form/SelectDropdown/styles.ts
dreamwasp e7cc7ac
merge main
dreamwasp d0c8703
Merge branch 'cass-gmt-292' of github.com:Codecademy/gamut into cass-…
dreamwasp f010705
fix syntax
dreamwasp bc91ff5
fix linting errors
dreamwasp 331c8ac
reorgnize
dreamwasp 8e8a130
fix errors
dreamwasp 53f4001
Merge branch 'main' into cass-gmt-292
dreamwasp e7a0f1a
amy fix
dreamwasp f781d4d
Update packages/gamut/agent-tools/skills/gamut-select-dropdown/SKILL.md
dreamwasp 7875d9d
Update packages/gamut/agent-tools/skills/gamut-select-dropdown/SKILL.md
dreamwasp bcfbe88
start kenny edits
dreamwasp ae462ba
Merge branch 'cass-gmt-292' of github.com:Codecademy/gamut into cass-…
dreamwasp 86275d8
Merge branch 'main' into cass-gmt-292
dreamwasp b3502b7
validation message, still tweaking
dreamwasp c07b2a4
Merge branch 'main' into cass-gmt-292
dreamwasp 03b5d3f
style: use classic /* */ block comments in useNoOptionsAnnouncement
dreamwasp cb6bddc
docs: fix SelectDropdown FormGroup wiring guidance, document no-optio…
dreamwasp 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
155 changes: 155 additions & 0 deletions
155
packages/gamut/agent-tools/skills/gamut-select-dropdown/SKILL.md
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,155 @@ | ||
| --- | ||
| name: gamut-select-dropdown | ||
| description: Use when implementing or auditing SelectDropdown — single/multi modes, controlled vs uncontrolled value, creatable options, FormGroup wiring, and react-select action meta. Pair with gamut-forms for FormGroup/validation patterns. | ||
| --- | ||
|
|
||
| # Gamut SelectDropdown | ||
|
|
||
| Styled dropdown built on react-select. Supports single and multi-select, searchable menus, creatable options, icons, groups, and abbreviations. | ||
|
|
||
| Source: `@codecademy/gamut` — [SelectDropdown.tsx](https://github.com/Codecademy/gamut/blob/main/packages/gamut/src/Form/SelectDropdown/SelectDropdown.tsx) | ||
|
|
||
| See also: [`gamut-forms`](../gamut-forms/SKILL.md) — FormGroup wiring, error regions, and validation UX. | ||
|
|
||
| Storybook: [Atoms / FormInputs / SelectDropdown](https://gamut.codecademy.com/?path=/docs-atoms-forminputs-selectdropdown--docs) | ||
|
|
||
| --- | ||
|
|
||
| ## When to use SelectDropdown vs Select | ||
|
|
||
| Use `Select` for standard single-select forms with minimal bundle cost. Use `SelectDropdown` when designs specify the styled dropdown menu, search, multi-select tags, creatable options, icons, groups, or abbreviations. SelectDropdown has a larger JavaScript dependency (react-select). | ||
|
|
||
| --- | ||
|
|
||
| ## Controlled vs uncontrolled | ||
|
|
||
| SelectDropdown does **not** accept `defaultValue`. | ||
|
dreamwasp marked this conversation as resolved.
Outdated
|
||
|
|
||
| | Mode | Uncontrolled | Controlled | | ||
| | ---------------- | -------------------------------------------------- | --------------------------------------------------------------------------------- | | ||
| | Single | Not supported | `value` (string) + update in `onChange` | | ||
| | Multi | Omit `value` or pass non-array (`undefined`, `''`) | `value: string[]` + update in `onChange` | | ||
| | Creatable single | Not supported | Same as single; `onCreateOption` appends to `options` | | ||
| | Creatable multi | Omit `value`; `onCreateOption` for options | `value: string[]`; update in `onChange` on every change including `create-option` | | ||
|
|
||
| Single-select selection is derived from the `value` prop only — internal state is not kept. Multi-select without `value: string[]` keeps selection in internal `multiValues`. | ||
|
|
||
| **Controlled creatable multi pitfall:** Updating `options` alone without syncing `value` in `onChange` clears selection when options re-render. | ||
|
|
||
| --- | ||
|
|
||
| ## onChange contract | ||
|
|
||
| `onChange` receives option object(s), not `event.target.value`: | ||
|
|
||
| ```tsx | ||
| // Single | ||
| onChange={(option) => setValue(option.value)} | ||
|
|
||
| // Multi | ||
| onChange={(selected) => setValue(selected.map((o) => o.value))} | ||
| ``` | ||
|
|
||
| Second argument is react-select `ActionMeta`. For creatable creates: `meta.action === 'create-option'`. Do **not** pass `onCreateOption` to react-select directly — Gamut invokes it from `changeHandler` while still forwarding `create-option` to consumer `onChange`. | ||
|
|
||
| --- | ||
|
|
||
| ## Creatable | ||
|
|
||
| - `isCreatable` forces `isSearchable: true` (TypeScript enforces this). | ||
| - `onCreateOption(inputValue)` — convenience hook to append to `options`. | ||
| - `onChange(selected, meta)` — use `meta.action === 'create-option'` to sync controlled `value` and `options` together. | ||
| - `isValidNewOption` — return `false` to hide the Add row. | ||
| - `validationMessage` — replaces menu "No options" text; mirror in `FormGroup` `error` for field-level feedback. | ||
|
|
||
| **Validation after blur:** react-select clears input on blur. Handle `onInputChange`: validate on `input-change`, re-validate from last typed value on `input-blur` so FormGroup error persists. | ||
|
|
||
| --- | ||
|
|
||
| ## FormGroup wiring | ||
|
|
||
| - `FormGroup` `htmlFor` must match control `id` / `name`. | ||
| - Pass `name` on SelectDropdown (required for forms). | ||
| - Pass `error` boolean when FormGroup has an error. | ||
| - Generic FormGroup live-region behavior: see [`gamut-forms`](../gamut-forms/SKILL.md). | ||
|
|
||
| ```tsx | ||
| <FormGroup htmlFor="country" isSoloField label="Country" error={errors.country}> | ||
| <SelectDropdown | ||
| name="country" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be |
||
| options={options} | ||
| value={value} | ||
| error={Boolean(errors.country)} | ||
| onChange={(option) => setValue(option.value)} | ||
| /> | ||
| </FormGroup> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Single (controlled) | ||
|
|
||
| ```tsx | ||
| const [value, setValue] = useState('us'); | ||
|
|
||
| <SelectDropdown | ||
| name="country" | ||
| options={options} | ||
| value={value} | ||
| onChange={(option) => setValue(option.value)} | ||
| />; | ||
| ``` | ||
|
|
||
| ### Multi (uncontrolled) | ||
|
|
||
| ```tsx | ||
| <SelectDropdown | ||
| multiple | ||
| name="tags" | ||
| options={options} | ||
| onChange={(selected) => console.log(selected)} | ||
| /> | ||
| ``` | ||
|
|
||
| ### Creatable multi (uncontrolled) | ||
|
|
||
| ```tsx | ||
| const [options, setOptions] = useState(['Apple', 'Banana']); | ||
|
|
||
| <SelectDropdown | ||
| isCreatable | ||
| multiple | ||
| name="fruits" | ||
| options={options} | ||
| onCreateOption={(v) => setOptions((prev) => [...prev, v])} | ||
| />; | ||
| ``` | ||
|
|
||
| ### Creatable multi (controlled) | ||
|
|
||
| ```tsx | ||
| const [options, setOptions] = useState(['Apple', 'Banana']); | ||
| const [value, setValue] = useState<string[]>([]); | ||
|
|
||
| <SelectDropdown | ||
| isCreatable | ||
| multiple | ||
| name="fruits" | ||
| options={options} | ||
| value={value} | ||
| onChange={(selected, meta) => { | ||
| setValue(selected.map((o) => o.value)); | ||
| if (meta.action === 'create-option' && meta.option) { | ||
| setOptions((prev) => [...prev, meta.option.value]); | ||
| } | ||
| }} | ||
| />; | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Storybook note | ||
|
|
||
| Default story args include `value: ''`. Spreading `{...args}` in custom renders behaves as controlled empty single. Omit `value` when demonstrating uncontrolled multi or creatable multi. | ||
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.
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.