Fixes #39311 - Allow selection clearance for AutocompleteInput#10983
Conversation
|
I'm setting |
|
Using arrows to navigate between the options is little bit weird because it jumps on first click, I will try to find solution how to deal with that. |
|
After the discussion we found that the |
There was a problem hiding this comment.
Pull request overview
This PR restores the ability to clear an AutocompleteInput selection (regression after the PF5 migration) by introducing an allowClear prop and opting the editor’s host selector out to preserve its existing behavior.
Changes:
- Add
allowClearprop toAutocompleteInput(defaulting to enabled) to clear selection when the input is emptied. - Refactor close/blur behavior in
AutocompleteInputto support the new clearing flow. - Disable clearing for the editor preview host selector via
allowClear={false}.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| webpack/assets/javascripts/react_app/components/Editor/components/EditorNavbar.js | Opts the editor host selector out of the new clear-on-empty behavior. |
| webpack/assets/javascripts/react_app/components/common/AutocompleteInput/AutocompleteInput.js | Adds allowClear and implements clear-on-empty logic plus related close handling. |
Comments suppressed due to low confidence (1)
webpack/assets/javascripts/react_app/components/common/AutocompleteInput/AutocompleteInput.js:147
- In
onTextInputChange, theallowClearpath usesselectedin a boolean context (... && selected), so clearing won’t fire for valid falsy selections (like0/false). Switch to an explicit “selection present” check to ensure clearing works for all supportedselectedtypes.
const onTextInputChange = (_event, value) => {
onChange(value);
setInputValue(value);
inputValueRef.current = value;
setFilterValue(value);
resetActiveAndFocusedItem();
if (allowClear && !value && selected) {
onSelect('');
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks, @Lukshio, I've dropped the custom onKeyDown logic, the component should now rely on what Patternfly does. Just for reference, before 57ae709: |
|
Changes looks good, ack. |
|
Re: https://github.com/theforeman/foreman/pull/10983/changes#r3279737043
Yeap, that's true. It is not an issue with current consumers since Editor won't trigger |
|
@ofedoren could you please squash? |
Fixes: 47dca75 - Explicitly check selected for empty values - Drop custom onKeyDown logic - Add tests - Fix linter failures - Fix onBlur stale value
e8e9b01 to
e3c58a5
Compare
|
I took the liberty of squashing it myself to squeeze it in time to get into 3.19.0rc2 |
Definitely not caused by the changes here |
|
Thank you @ofedoren ! |
Fixes: 47dca75
Before:
before.webm
After:
after.webm
For context please see the attachments or the ticket.
I believe this is a regression caused by #10777, but since the only consumer outside is webhooks plugin, the issue was missed and caught by CI runs of the plugin. We could fix that in the plugin, but since that commit changed behavior by essentially breaking functionality, I'd rather return back what was changed.
I'm not sure about the approach of the fix much, I've tried to make it in a way that it leaves what EditorHostSelect needs, but at the same time the same behavior might be re-used by other consumers via
allowClearprop if needed.I doubt we'll manage to get this before branching, so I treat it as a separate issue that follows the previous PR, thus Fixes instead of Refs. If we won't manage to get this before branching, we'll need to cherry-pick it into 3.19-stable.
cc @adamlazik1, @Lukshio, @MariaAga
UPD: The CI with this patch is green: theforeman/foreman_webhooks#101