Skip to content

Fixes #39311 - Allow selection clearance for AutocompleteInput#10983

Merged
adamruzicka merged 1 commit into
theforeman:developfrom
ofedoren:bug-39311-fix-autocomplete
May 26, 2026
Merged

Fixes #39311 - Allow selection clearance for AutocompleteInput#10983
adamruzicka merged 1 commit into
theforeman:developfrom
ofedoren:bug-39311-fix-autocomplete

Conversation

@ofedoren
Copy link
Copy Markdown
Member

@ofedoren ofedoren commented May 11, 2026

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 allowClear prop 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

@github-actions github-actions Bot added the UI label May 11, 2026
@ogajduse ogajduse added the Needs cherrypick This should be cherrypicked to the stable branches or branches label May 12, 2026
@ogajduse
Copy link
Copy Markdown
Member

I'm setting Needs cherrypick label as https://projects.theforeman.org/issues/39311 targets 3.19.0 that was branched today.

@Lukshio
Copy link
Copy Markdown
Contributor

Lukshio commented May 13, 2026

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.

@Lukshio
Copy link
Copy Markdown
Contributor

Lukshio commented May 19, 2026

After the discussion we found that the onKeyDown prop can be deleted and also the helper functions. Probably due to package update with fixed issue.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 allowClear prop to AutocompleteInput (defaulting to enabled) to clear selection when the input is emptied.
  • Refactor close/blur behavior in AutocompleteInput to 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, the allowClear path uses selected in a boolean context (... && selected), so clearing won’t fire for valid falsy selections (like 0/false). Switch to an explicit “selection present” check to ensure clearing works for all supported selected types.
  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.

@ofedoren
Copy link
Copy Markdown
Member Author

Thanks, @Lukshio, I've dropped the custom onKeyDown logic, the component should now rely on what Patternfly does.

Just for reference, before 57ae709:
before.webm
After 57ae709:
after.webm

@Lukshio
Copy link
Copy Markdown
Contributor

Lukshio commented May 21, 2026

Changes looks good, ack.

@ofedoren
Copy link
Copy Markdown
Member Author

Re: https://github.com/theforeman/foreman/pull/10983/changes#r3279737043

But wouldn't the onBlur get called with possibly stale displayValue?

Yeap, that's true. It is not an issue with current consumers since Editor won't trigger true branch and webhooks don't use custom onBlur (uses noop from the defaults). But just in case for future consumers it should be fixed now.

@adamruzicka
Copy link
Copy Markdown
Contributor

@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
@adamruzicka adamruzicka force-pushed the bug-39311-fix-autocomplete branch from e8e9b01 to e3c58a5 Compare May 26, 2026 10:32
@adamruzicka
Copy link
Copy Markdown
Contributor

I took the liberty of squashing it myself to squeeze it in time to get into 3.19.0rc2

@adamruzicka
Copy link
Copy Markdown
Contributor

Download action repository 're-actors/alls-green@release/v1' (SHA:05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe)
Error: An action could not be found at the URI 'https://codeload.github.com/re-actors/alls-green/tar.gz/05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe' (2440:163F83:19DADA:209FBA:6A157D9B)
Error: Failed to download archive 'https://codeload.github.com/re-actors/alls-green/tar.gz/05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe' after 1 attempts.

Definitely not caused by the changes here

@adamruzicka adamruzicka merged commit eb7284c into theforeman:develop May 26, 2026
25 of 26 checks passed
@adamruzicka
Copy link
Copy Markdown
Contributor

Thank you @ofedoren !

@adamruzicka
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs cherrypick This should be cherrypicked to the stable branches or branches UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants