Skip to content

Clearing selection and search  #2

Description

@danyill

Between re-renderings of a selection list, I want to clear the checkboxes and reset the search value.

I found this difficult to do -- perhaps an internal method or property to enable this would be good:

Here's what I'm doing:

  clearSelection(): void {
    if (this.selectionList) {
      (
        Array.from(
          this.selectionList.shadowRoot!.querySelectorAll(
            'md-list.listitems md-list-item md-checkbox',
          ),
        ) as MdCheckbox[]
      ).forEach((cb): void => {
        if (cb.checked) {
          // eslint-disable-next-line no-param-reassign
          cb.checked = false;
          cb.dispatchEvent(new Event('change'));
          cb.requestUpdate();
        }
      });

      const searchField = (this.selectionList.shadowRoot!.querySelector(
        'md-outlined-text-field[placeholder="search"]',
      ) as MdOutlinedTextField)!;
      searchField.value = '';
      searchField.dispatchEvent(new Event('input'));
    }
  }

It may be that I'm using it incorrectly of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions