Add support for creating custom options in Autocomplete
Describe your changes:
Fixes 29443
I worked on ... because ...
Type of change:
- [ ] Bug fix
- [ ] Improvement
- [ ] New feature
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation
High-level design:
N/A โ small change.
Tests:
Use cases covered
Unit tests
Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
UI screen recording / screenshots:
Not applicable.
Checklist:
- [x] I have read the CONTRIBUTING document.
- [ ] My PR title is
Fixes <issue-number>: <short explanation> - [ ] My PR is linked to a GitHub issue via
Fixes #<issue-number>above. - [ ] I have commented on my code, particularly in hard-to-understand areas.
- [ ] For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
- [ ] For UI changes: I attached a screen recording and/or screenshots above.
- [ ] I have added tests (unit / integration / Playwright as applicable) and listed them above.
Greptile Summary
This PR adds an allowsCreation prop to the Autocomplete component that lets users type a custom value and commit it (via Enter or blur) as a new selectable item, wiring the feature through FieldPropsMap and renderFieldElement. It also adds the missing onFocus forwarding to several field types (Input, TextArea, Toggle, Checkbox, Select).
- Core creation logic (
autocomplete.tsx): IntroducesonCreateItem, an Enter-key guard, and anonBlurhandler; has multiple interaction bugs where creation fires incorrectly when the dropdown is open or when the user clicks an existing item (see inline comments). - Form field wiring (
render-field-element.tsx): Correctly falls back to a synthetic item inhandleInsertwhenallowsCreationis set and the key is not in the item list;onFocusforwarding additions are clean. - Stories (
Autocomplete.stories.tsx): Three representative stories cover multi-select, single-select, and pre-selected scenarios.
Confidence Score: 3/5
The new allowsCreation feature has interaction bugs that will cause wrong items to be selected or duplicates to be created in normal keyboard and mouse workflows; needs fixes before merging.
Three distinct defects exist in the core creation flow: the Enter handler intercepts keyboard selection of highlighted dropdown items, the blur handler fires before click-based selection commits (creating a spurious item and blocking the intended one in single-select mode), and onCreateItem does not respect the multiple={false} cap. Each bug is reachable through the primary user interactions the feature is designed to support.
autocomplete.tsx โ all three issues are in the InnerAutocomplete keydown/blur handlers and the AutocompleteBase.onCreateItem callback.
Important Files Changed
| Filename | Overview |
|---|---|
| openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx | Adds allowsCreation prop with Enter-key and blur-triggered item creation; has three behavioral bugs: Enter intercepts existing-item selection when the dropdown is open, blur fires before listbox click selection causing wrong item creation, and onCreateItem does not enforce the multiple={false} limit. |
| openmetadata-ui-core-components/src/main/resources/ui/src/components/application/form-field/render-field-element.tsx | Wires allowsCreation into handleInsert fallback and correctly passes onFocus to previously-missing field types (Input, TextArea, Toggle, Checkbox, Select); logic is straightforward and correct. |
| openmetadata-ui-core-components/src/main/resources/ui/src/components/application/form-field/form-field.types.ts | Adds allowsCreation?: boolean to FieldPropsMap; trivial type-only change, no issues. |
| openmetadata-ui-core-components/src/main/resources/ui/src/stories/Autocomplete.stories.tsx | Adds three Storybook stories for the new allowsCreation feature; stories are well-structured and cover multi-select, single-select, and pre-selected scenarios. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant User
participant AriaInput
participant InnerAutocomplete
participant AutocompleteBase
participant Dropdown
Note over User,Dropdown: Happy path โ user types & presses Enter (dropdown closed)
User->>AriaInput: type "foo"
AriaInput->>AutocompleteBase: onInputChange("foo")
User->>AriaInput: keydown Enter
AriaInput->>InnerAutocomplete: handleInputKeyDown(Enter)
InnerAutocomplete->>AutocompleteBase: onCreateItem("foo")
AutocompleteBase->>AutocompleteBase: add to allItems + internalSelected
Note over User,Dropdown: Bug path โ user types & presses Enter (dropdown open + item highlighted)
User->>AriaInput: type "rea"
AriaInput->>Dropdown: opens, highlights "React"
User->>AriaInput: keydown Enter
AriaInput->>InnerAutocomplete: handleInputKeyDown(Enter)
InnerAutocomplete-->>AutocompleteBase: onCreateItem("rea") โ wrong: creates custom item
Dropdown-->>AutocompleteBase: onSelectionChange("React") โ also fires (react-aria)
Note over User,Dropdown: Bug path โ user types & clicks existing dropdown item
User->>AriaInput: type "foo"
User->>Dropdown: click "Foo"
Dropdown->>AriaInput: pointerdown triggers blur on input
AriaInput->>InnerAutocomplete: "onBlur(value="foo")"
InnerAutocomplete-->>AutocompleteBase: onCreateItem("foo") โ spurious creation
Dropdown->>AutocompleteBase: onSelectionChange("Foo") โ blocked in single-select
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant User
participant AriaInput
participant InnerAutocomplete
participant AutocompleteBase
participant Dropdown
Note over User,Dropdown: Happy path โ user types & presses Enter (dropdown closed)
User->>AriaInput: type "foo"
AriaInput->>AutocompleteBase: onInputChange("foo")
User->>AriaInput: keydown Enter
AriaInput->>InnerAutocomplete: handleInputKeyDown(Enter)
InnerAutocomplete->>AutocompleteBase: onCreateItem("foo")
AutocompleteBase->>AutocompleteBase: add to allItems + internalSelected
Note over User,Dropdown: Bug path โ user types & presses Enter (dropdown open + item highlighted)
User->>AriaInput: type "rea"
AriaInput->>Dropdown: opens, highlights "React"
User->>AriaInput: keydown Enter
AriaInput->>InnerAutocomplete: handleInputKeyDown(Enter)
InnerAutocomplete-->>AutocompleteBase: onCreateItem("rea") โ wrong: creates custom item
Dropdown-->>AutocompleteBase: onSelectionChange("React") โ also fires (react-aria)
Note over User,Dropdown: Bug path โ user types & clicks existing dropdown item
User->>AriaInput: type "foo"
User->>Dropdown: click "Foo"
Dropdown->>AriaInput: pointerdown triggers blur on input
AriaInput->>InnerAutocomplete: "onBlur(value="foo")"
InnerAutocomplete-->>AutocompleteBase: onCreateItem("foo") โ spurious creation
Dropdown->>AutocompleteBase: onSelectionChange("Foo") โ blocked in single-select
Reviews (1): Last reviewed commit: "Add support for creating custom options ..." | Re-trigger Greptile
Greptile also left 3 inline comments on this PR.
๐ก Playwright Results โ all passed (22 flaky)
โ 4448 passed ยท โ 0 failed ยท ๐ก 22 flaky ยท โญ๏ธ 88 skipped
| Shard | Passed | Failed | Flaky | Skipped |
|---|---|---|---|---|
| ๐ก Shard 1 | 323 | 0 | 2 | 4 |
| ๐ก Shard 2 | 830 | 0 | 7 | 9 |
| ๐ก Shard 3 | 836 | 0 | 3 | 7 |
| ๐ก Shard 4 | 833 | 0 | 3 | 10 |
| ๐ก Shard 5 | 833 | 0 | 1 | 50 |
| ๐ก Shard 6 | 793 | 0 | 6 | 8 |
๐ก 22 flaky test(s) (passed on retry)
Pages/SearchSettings.spec.tsโบ Preview config reflects reverted n-gram weight after save (shard 1, 1 retry)Flow/SearchRBAC.spec.tsโบ a fully denied user sees neither asset type when browsing (shard 1, 2 retries)Features/BulkEditEntity.spec.tsโบ Glossary (shard 2, 1 retry)Features/BulkEditOperationBadges.spec.tsโบ Glossary bulk edit search filters rows and clear restores them (shard 2, 1 retry)Features/BulkEditOperationBadges.spec.tsโบ Database service bulk edit search filters rows and clear restores them (shard 2, 1 retry)Features/BulkImport.spec.tsโบ Database Schema (shard 2, 1 retry)Features/BulkImportWithDotInName.spec.tsโบ CSV with quoted FQN loads correctly in import grid (shard 2, 1 retry)Features/DataQuality/DataQuality.spec.tsโบ Table test case (shard 2, 1 retry)Features/DataQuality/TestLibrary.spec.tsโบ should maintain page on edit and reset to first page on delete (shard 2, 1 retry)Features/SearchExport.spec.tsโบ Export queues a background job and downloads from the jobs tray (shard 3, 1 retry)Features/Table.spec.tsโบ Table pagination with sorting should works (shard 3, 1 retry)Features/Tasks/TaskNavigation.spec.tsโบ navigating to /table/TASK-XXXXX should show 404 (invalid URL pattern) (shard 3, 1 retry)Flow/PersonaFlow.spec.tsโบ Set default persona for team should work properly (shard 4, 1 retry)Pages/CustomProperties.spec.tsโบ Date (shard 4, 1 retry)Pages/CustomProperties.spec.tsโบ Should clear search and show all properties for apiCollection in right panel (shard 4, 1 retry)Pages/ExplorePageRightPanel_KnowledgeCenter.spec.tsโบ Should remove user owner for knowledgeCenter (shard 5, 1 retry)Pages/GlossaryImportExport.spec.tsโบ Check for Circular Reference in Glossary Import (shard 6, 1 retry)Pages/GlossaryImportExport.spec.tsโบ Import partial success - some terms pass, some fail (shard 6, 1 retry)Pages/Lineage/LineageFilters.spec.tsโบ Verify lineage schema filter selection (shard 6, 1 retry)Pages/Lineage/LineageRightPanel.spec.tsโบ Verify custom properties tab IS visible for supported type: searchIndex (shard 6, 1 retry)Pages/Lineage/PlatformLineage.spec.tsโบ Verify domain platform view (shard 6, 1 retry)Pages/ServiceEntity.spec.tsโบ Announcement create, edit & delete (shard 6, 1 retry)
๐ฆ Download artifacts
How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace
Jest test Coverage
UI tests summary
| Lines | Statements | Branches | Functions |
|---|---|---|---|
| 63.42% (70680/111437) | 45.9% (40625/88504) | 47.81% (12367/25864) |
Quality Gate passed for 'open-metadata-ui'
Issues
1241 New issues
0 Accepted issues
Measures
13 Security Hotspots
0.0% Coverage on New Code
3.4% Duplication on New Code
Adds ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:139-153
In Consider only creating when there is no active/focused option in the ComboBox state (e.g. check ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:431-445 ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:405-411
๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:276-281
The ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:450-461 ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/application/form-field/render-field-element.tsx
The delta moved Before this commit, Fix: call ๐ openmetadata-ui-core-components/src/main/resources/ui/src/components/base/autocomplete/autocomplete.tsx:450-464
Consider computing the dedup decision against the current Display: compact โ Showing less information. Comment with these commands to change:Code Review โ
Approved 5 resolved / 5 findings
allowsCreation and hideDropdown functionality to the Autocomplete component to support custom free-form options. All reported issues, including spurious item creation on blur and side effects within state updates, have been resolved.โ
5 resolved
โ
Bug: Enter always creates new item, blocking selection of highlighted option
handleInputKeyDown, when allowsCreation is true and the input is non-empty, pressing Enter unconditionally calls event.preventDefault() and context.onCreateItem?.(inputValue.trim()), then returns. This runs before/instead of the ComboBox's default Enter behavior that selects the currently highlighted option. As a result, a user who types a filter (e.g. "Ali"), arrows down to an existing option ("Alice Johnson") and presses Enter will create a brand-new item "Ali" instead of selecting the existing option. Keyboard selection of existing items becomes impossible whenever creation is enabled.comboBoxStateContext.selectionManager.focusedKey is null) before short-circuiting to onCreateItem, otherwise fall through to default selection.โ
Bug: onCreateItem ignores multiple=false, allowing many items in single-select
onSelectionChange guards single-select with if (!multiple && internalSelected.length >= 1) return;, but the new onCreateItem callback has no such guard. It always appends the created item to internalSelected. In single-select mode (multiple={false}, e.g. the AllowsCreationSingleSelect story), repeatedly creating values accumulates multiple selected items, violating the single-selection contract. Mirror the guard from onSelectionChange: in single-select, replace the selection (or bail when one already exists) instead of pushing. Also add multiple to the useCallback dependency array.โ
Edge Case: onBlur auto-creates spurious items from leftover filter text
AriaInput onBlur handler creates an item from any non-empty trimmed input value when allowsCreation is set. This fires whenever the input loses focus, including when the user typed a search filter intending to pick an existing option, or simply clicked away without wanting to create anything. In particular, selecting an existing option by mouse can leave residual filter text that then gets turned into an unintended custom item on blur. Consider only creating on an explicit commit action (Enter), or skipping blur-creation when a dropdown option is being selected / the value matches an existing item's label.โ
Bug: Single-select create-replace no longer notifies form value
onItemInserted?.(value) from an unconditional call (previously outside the updater) to inside the setInternalSelected updater's !alreadySelected branch. The single-select replacement branch (if (!multiple && prev.length >= 1) { return [newItem]; }) now returns the new item but never calls onItemInserted.onItemInserted fired unconditionally after the updater, so this path worked. Now, in single-select mode with allowsCreation, if an item is already selected and the user creates a new custom value (Enter/blur), internalSelected is replaced with [newItem] โ so the chip UI shows the new value โ but onItemInserted is never invoked. Consequently handleInsert in render-field-element.tsx never calls field.onChange, and the react-hook-form value retains the OLD selection. The visible chip and the committed form value diverge silently until submission.onItemInserted?.(value) in the replacement branch as well (or restructure to compute the decision outside the updater).โ
Quality: Side effect (onItemInserted) called inside setState updater
onItemInserted?.(value) is invoked inside the setInternalSelected updater callback. State updater functions should be pure; React intentionally double-invokes updaters in StrictMode (development) to surface impurity, which would fire onItemInserted โ and therefore field.onChange/any parent side effects โ twice during development. It also makes the logic harder to reason about and may trip strict lint rules.internalSelected outside the updater (adding it to the useCallback deps) and calling onItemInserted from the effectful body rather than from within the state updater.Options
Compact
gitar display:verbose
Was this helpful? React with ๐ / ๐ | Gitar