Skip to content

Clear Button Plugin

The clear-button plugin adds a button that clears all selected items at once. This is particularly useful for multiple-select elements with many selections.

Usage

Behavior

  • A "Clear all" button appears inside the control area when at least one item is selected
  • Clicking the button removes all selections at once
  • The button automatically hides when no items are selected
  • The ds:clear event fires when the button is clicked

Difference from data-allow-clear

Featuredata-allow-clearclear-button plugin
Best forSingle selectMultiple select
IconSmall "x" near the arrowDistinct "Clear all" button
BehaviorClears the single valueClears all selected items
Requires placeholder optionYesNo

Example with Remove Button

Combine with remove-button for full control — remove individual items or clear all:

Styling

The clear button uses the .ds-clear-all CSS class:

css
.dot-select .ds-clear-all {
  font-size: 12px;
  color: #64748b;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.dot-select .ds-clear-all:hover {
  background-color: #fee2e2;
  color: #dc2626;
}

Accessibility

The clear button includes an aria-label with the localized "Clear all" text from the active locale's clearAll key.

MIT Licensed