Skip to content

ComboBox: set empty value if no match on filter #11636

@rolfsmeds

Description

@rolfsmeds

Describe your motivation

Currently, if the text typed into the ComboBox doesn't match any item, the field automatically reverts to its previous value on enter/blur.

This can cause issues if the user doesn't notice the non-match, and thus does not notice that the ComboBox still has its previous value.

In many cases, it would be better if the ComboBox set itself to the empty value, so that a required validation on the field would catch it.

Describe the solution you'd like

An API for toggling the non-match behavior between

  • Revert to previous value
  • Fall back to empty value

The Flow API could be something along the lines of
ComboBox::setNoMatchBehavior(NoMatchBehavior) where NoMatchBehavior is an enum of REVERT and EMPTY.

The WC/React API could be a corresponding noMatchBehavior property of revert and empty.

Alternatively, a boolean could probably be sufficiently descriptive: setEmptyOnNoMatch(true) and emptyOnNoMatch respectively.

Ideally, we would provide a global switch for this in Flow through a static setter like
ComboBox.setNoMatchBehavior(NoMatchBehavior)

This API should also be available in MultiSelectComboBox.

Describe alternatives you've considered

The desired behavior, as described above, might actually be a better default, but changing it now would be a breaking change.

We could consider changing the default in V26.0.

Additional context

In combination with allowCustomValues, the CustomValueSetListener can be used to achieve the desired behavior. The proposed API would have no effect when used in combination with allowCustomValues.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions