Skip to content

Is it possible to clear the input programatically #334

Open
@richtier

Description

@richtier

I would like to clear the input box programmatically. I've almost made it work, but the result is the dropdown opens again ad a side effect.

clear

I'm doing this:

   accessibleAutocomplete({
      element: containerElement,
      selectElement: multiselectElement,
      defaultValue: '',
      confirmOnBlur: false,
      showAllValues: true,
      id: autocompleteId,
      onConfirm: handleAdd,
      source: getSource
    });
    function handleAdd(value) {
      // hack to clear the input box. delay 150ms to allow the react component
      // to render iwth the new value first.
      // hide the selected value by making it the same colour as the input box
      autocompleteInputElement.style.color = 'white';
      setTimeout(function() {
        autocompleteInputElement.value = '';
        autocompleteInputElement.style.color = 'black';
      }, 150);
    }

yes., it's a horrible hack and is subject to race condition. is there a built-in way?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions