Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/select

Package Overview
Dependencies
Maintainers
15
Versions
1696
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/select

The Material Components web select (text field drop-down) component

  • 14.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
615K
decreased by-14.86%
Maintainers
15
Weekly downloads
 
Created
Source

Select Menus

MDC Select provides Material Design single-option select menus, using the MDC menu. The Select component is fully accessible, and supports RTL rendering.

Important Changes

Select is currently being updated to use the new List implementation. For now, please continue to use the old implementation (mdc-deprecated-list and associated DOM/classes) instead of the new one (mdc-list).

See the List documentation for more information.

Design & API Documentation

Installation

npm install @material/select

Basic Usage

The select uses an MDCMenu component instance to contain the list of options, but uses the data-value attribute instead of value to represent the options' values.

NOTE: The data-value attribute must be present on each option.

The select requires that you set the width of the mdc-select element. This is best done through the use of another class (e.g. demo-width-class in the example HTML and CSS below).

HTML

The HTML for the select component follows the WAI-ARIA recommendations for Collapsible Dropdown Listboxes in order to meet WCAG and ARIA accessibility standards, and to be compatible with assistive technology like screen readers.

The following example applies ARIA attributes that provide the semantic structure required for assistive technology:

<div class="mdc-select mdc-select--filled demo-width-class">
  <div class="mdc-select__anchor"
       role="button"
       aria-haspopup="listbox"
       aria-expanded="false"
       aria-labelledby="demo-label demo-selected-text">
    <span class="mdc-select__ripple"></span>
    <span id="demo-label" class="mdc-floating-label">Pick a Food Group</span>
    <span class="mdc-select__selected-text-container">
      <span id="demo-selected-text" class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
    <span class="mdc-line-ripple"></span>
  </div>

  <div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
    <ul class="mdc-deprecated-list" role="listbox" aria-label="Food picker listbox">
      <li class="mdc-deprecated-list-item mdc-deprecated-list-item--selected" aria-selected="true" data-value="" role="option">
        <span class="mdc-deprecated-list-item__ripple"></span>
      </li>
      <li class="mdc-deprecated-list-item" aria-selected="false" data-value="grains" role="option">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">
          Bread, Cereal, Rice, and Pasta
        </span>
      </li>
      <li class="mdc-deprecated-list-item mdc-deprecated-list-item--disabled" aria-selected="false" data-value="vegetables" aria-disabled="true" role="option">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">
          Vegetables
        </span>
      </li>
      <li class="mdc-deprecated-list-item" aria-selected="false" data-value="fruit" role="option">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">
          Fruit
        </span>
      </li>
    </ul>
  </div>
</div>

NOTE: The menu width matches the width of the select by default. To set menu to its natural width, remove mdc-menu-surface--fullwidth from the menu surface.

Styles

When using the select, you will also need to load the Menu and List components' styles.

@use "@material/list/mdc-list";
@use "@material/menu-surface/mdc-menu-surface";
@use "@material/menu/mdc-menu";
@use "@material/select/styles";

.demo-width-class {
  width: 400px;
}

Theming

@use '@material/select';

.my-demo-select {
  @include select.filled-density(-2);
}

JavaScript Instantiation

import {MDCSelect} from '@material/select';

const select = new MDCSelect(document.querySelector('.mdc-select'));

select.listen('MDCSelect:change', () => {
  alert(`Selected option at index ${select.selectedIndex} with value "${select.value}"`);
});

See Importing the JS component for more information on how to import JavaScript.

Variants

Outlined Select

The Select Outlined variant uses the mdc-notched-outline in place of the mdc-line-ripple element and adds the mdc-select--outlined modifier class on the root element. All other elements for each type of select remain the same.

<div class="mdc-select mdc-select--outlined">
  <div class="mdc-select__anchor" aria-labelledby="outlined-select-label">
    <span class="mdc-notched-outline">
      <span class="mdc-notched-outline__leading"></span>
      <span class="mdc-notched-outline__notch">
        <span id="outlined-select-label" class="mdc-floating-label">Pick a Food Group</span>
      </span>
      <span class="mdc-notched-outline__trailing"></span>
    </span>
    <span class="mdc-select__selected-text-container">
      <span id="demo-selected-text" class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
  </div>

  <!-- Other elements from the select remain. -->
  <div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">...</div>
</div>

Additional Information

Select with hidden input (for HTML forms)

For convenient submission of Select's value in HTML forms, a hidden input element may be added under the root element. The component will synchronize its value with that of the hidden input.

<div class="mdc-select mdc-select--filled demo-width-class">
  <input type="hidden" name="demo-input">
  <div class="mdc-select__anchor">
    <!-- Rest of component omitted for brevity -->
  </div>
</div>

Select with pre-selected option

To indicate a select component that has a pre-selected value, use the mdc-deprecated-list-item--selected class to set the selected item. The select also needs the text from the selected element copied to the mdc-select__selected-text element.

<div class="mdc-select mdc-select--filled demo-width-class">
  <div class="mdc-select__anchor">
    <span class="mdc-select__ripple"></span>
    <span class="mdc-floating-label mdc-floating-label--float-above">Pick a Food Group</span>
    <span class="mdc-select__selected-text-container">
      <span class="mdc-select__selected-text">Vegetables</span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
    <span class="mdc-line-ripple"></span>
  </div>

  <div class="mdc-select__menu demo-width-class mdc-menu mdc-menu-surface">
    <ul class="mdc-deprecated-list">
      <li class="mdc-deprecated-list-item" data-value="">
        <span class="mdc-deprecated-list-item__ripple"></span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="grains">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Bread, Cereal, Rice, and Pasta</span>
      </li>
      <li class="mdc-deprecated-list-item mdc-deprecated-list-item--selected" data-value="vegetables" aria-selected="true">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Vegetables</span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="fruit">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Fruit</span>
      </li>
    </ul>
  </div>
</div>
Using the floating label as the placeholder

Leave the mdc-select__selected-text element empty and don't specify an element as selected. If leaving the field empty should be a valid option, include an mdc-deprecated-list-item element at the beginning of the list with an empty data-value attribute.

<li class="mdc-deprecated-list-item mdc-deprecated-list-item--selected" aria-selected="true" role="option" data-value=""></li>
Required select

To style a select menu as required and enable validation, add the mdc-select--required class to the mdc-select element and set the aria-required attribute on the mdc-select__anchor element to be "true".

<div class="mdc-select mdc-select--filled mdc-select--required">
  <div class="mdc-select__anchor" aria-required="true">
    <span class="mdc-select__ripple"></span>
    <span class="mdc-floating-label">Pick a Food Group</span>
    <span class="mdc-select__selected-text-container">
      <span class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
    <span class="mdc-line-ripple"></span>
  </div>

  <div class="mdc-select__menu mdc-menu mdc-menu-surface">
    ...
  </div>
</div>

NOTE: To programmatically set a select as required, use the required property in the MDCSelect API.

Disabled select

Add the mdc-select--disabled class to the mdc-select element, set the aria-disabled attribute on the mdc-select__selected-text element to be "true", and set the disabled attribute any hidden input element.

<div class="mdc-select mdc-select--filled mdc-select--disabled">
  <div class="mdc-select__anchor" aria-disabled="true">
    <span class="mdc-select__ripple"></span>
    <span class="mdc-floating-label">Pick a Food Group</span>
    <span class="mdc-select__selected-text-container">
      <span class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
    <span class="mdc-line-ripple"></span>
  </div>

  <div class="mdc-select__menu mdc-menu mdc-menu-surface">
    ...
  </div>
</div>

NOTE: To programmatically set a select as disabled, use the disabled property in the MDCSelect API.

Disabled options

Add the mdc-deprecated-list-item--disabled class to list items that are disabled. Disabled list items are removed from the list items index and are ignored entirely. You cannot programmatically select a disabled list item.

<div class="mdc-select mdc-select--filled">
  <div class="mdc-select__anchor">
    ...
  </div>

  <div class="mdc-select__menu mdc-menu mdc-menu-surface">
    <ul class="mdc-deprecated-list">
      <li class="mdc-deprecated-list-item" data-value="">
        <span class="mdc-deprecated-list-item__ripple"></span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="grains">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Bread, Cereal, Rice, and Pasta</span>
      </li>
      <li class="mdc-deprecated-list-item mdc-deprecated-list-item--selected mdc-deprecated-list-item--disabled" data-value="vegetables">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Vegetables</span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="fruit">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Fruit</span>
      </li>
    </ul>
  </div>
</div>

Select with Helper Text

The helper text provides supplemental information and/or validation messages to users. It appears when the select element is focused and disappears on blur by default, or it can be persistent. See here for more information on using helper text.

Select with Leading Icons

Leading icons can be added within the default or outlined variant of MDC Select as visual indicators as well as interaction targets. See here for more information on using icons.

Select with No Label

A label is not required if a separate, adjacent label is provided elsewhere. To correctly style MDC Select without a label, add the class mdc-select--no-label and remove the label from the structure.

Filled
<div class="mdc-select mdc-select--filled mdc-select--no-label demo-width-class">
  <div class="mdc-select__anchor">
    <span class="mdc-select__ripple"></span>
    <span class="mdc-select__selected-text-container">
      <span class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
    <span class="mdc-line-ripple"></span>
  </div>

  <div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">
    <ul class="mdc-deprecated-list">
      <li class="mdc-deprecated-list-item mdc-deprecated-list-item--selected" data-value="" aria-selected="true">
        <span class="mdc-deprecated-list-item__ripple"></span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="grains">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Bread, Cereal, Rice, and Pasta</span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="vegetables">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Vegetables</span>
      </li>
      <li class="mdc-deprecated-list-item" data-value="fruit">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <span class="mdc-deprecated-list-item__text">Fruit</span>
      </li>
    </ul>
  </div>
</div>
Outlined
<div class="mdc-select mdc-select--outlined mdc-select--no-label demo-width-class">
  <div class="mdc-select__anchor">
    <span class="mdc-notched-outline">
      <span class="mdc-notched-outline__leading"></span>
      <span class="mdc-notched-outline__trailing"></span>
    </span>
    <span class="mdc-select__selected-text-container">
      <span class="mdc-select__selected-text"></span>
    </span>
    <span class="mdc-select__dropdown-icon">
      <svg
          class="mdc-select__dropdown-icon-graphic"
          viewBox="7 10 10 5" focusable="false">
        <polygon
            class="mdc-select__dropdown-icon-inactive"
            stroke="none"
            fill-rule="evenodd"
            points="7 10 12 15 17 10">
        </polygon>
        <polygon
            class="mdc-select__dropdown-icon-active"
            stroke="none"
            fill-rule="evenodd"
            points="7 15 12 10 17 15">
        </polygon>
      </svg>
    </span>
  </div>

  <!-- Other elements from the select remain. -->
  <div class="mdc-select__menu mdc-menu mdc-menu-surface mdc-menu-surface--fullwidth">...</div>
</div>

Style Customization

CSS Classes
ClassDescription
mdc-selectMandatory.
mdc-select__anchorMandatory. This element should be placed within the mdc-select element.
mdc-select__menuMandatory. This class should be placed on the mdc-menu element within the mdc-select element.
mdc-select__dropdown-iconMandatory. Should be placed on an i element within the mdc-select__anchor element. Used for the dropdown arrow svg and animation.
mdc-select__selected-text-containerMandatory. This class wraps the mdc-select__selected-text and facilitates text-overflow: ellipsis on it.
mdc-select__selected-textMandatory. This class should be placed on a span within the mdc-select__anchor element.
mdc-select__iconOptional. Should be placed on an i or svg element within the mdc-select__anchor element. Used for the leading icon.
mdc-select--activatedOptional. Styles the activated state of select. This class will be added automatically when menu is opened.
mdc-select--disabledOptional. Styles the select as disabled. This class should be applied to the root element when the disabled attribute is applied to the <select> element.
mdc-select--outlinedOptional. Styles the select as outlined select.
mdc-select--with-leading-iconStyles the select as a select with a leading icon.
mdc-select--no-labelStyles the select as a select without a label.

NOTE: To further customize the MDCMenu or the MDCList component contained within the select, please refer to their respective documentation.

Sass Mixins

Mixins should be included in the context of a custom class applied to the component's root element, e.g. .my-select.

MixinDescription
ink-color($state)Customizes the color of the selected item displayed in the select. Accepts a Map for default and disabled states.
container-fill-color($state)Customizes the background color of the select. Accepts a Map for default and disabled states.
dropdown-icon-color($state)Customizes the dropdown icon color of the select. Accepts a Map for default, hover, focus, and disabled states.
label-color($state)Customizes the label color of the select. Accepts a Map for default, hover, focus, and disabled states.
label-floating-color($state)Customizes the label color of the select when the label is floating. Accepts a Map for default and hover states.
bottom-line-color($state)Customizes the color of the bottom line of the select. Accepts a Map for default, hover, focus, and disabled states.
filled-shape-radius($radius, $density-scale, $rtl-reflexive)Sets rounded shape to filled select variant with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to false.
outline-color($state)Customizes the color of the notched outline. Accepts a Map for default, hover, focus, and disabled states.
outline-shape-radius($radius, $density-scale, $rtl-reflexive)Sets the border radius of the outlined select variant. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to false.
filled-density($density-scale)Sets density scale for the filled select variant (Excluding filled select with leading icon).
filled-with-leading-icon-density($density-scale)Sets density scale for filled select with leading icon.
outlined-density($density-scale)Sets density scale for outlined select (Excluding outlined select with leading icon).
outlined-with-leading-icon-density($density-scale)Sets density scale for outlined select with leading icon.
filled-height($height)Sets height of the filled select variant (Excluding filled select with leading icon).
filled-with-leading-icon-height($height)Sets height of filled select with leading icon variant.
outlined-height($height)Sets height of outlined select variant (Excluding outlined select with leading icon).
outlined-with-leading-icon-height($height)Sets height of outlined select with leading icon variant.
variable-width($min-width)Sets the select behavior to change width dynamically based on content.

NOTE: To further customize the floating label, please see the floating label documentation.

MDCSelect API

The MDCSelect component API is modeled after a subset of the HTMLSelectElement functionality.

PropertyTypeDescription
valuestringThe value/data-value of the currently selected option.
selectedIndexnumberThe index of the currently selected option. Set to -1 if no option is currently selected. Changing this property will update the select element.
disabledbooleanWhether or not the component is disabled. Setting this sets the disabled state on the component.
useDefaultValidationbooleanWhether or not to use the default validation scheme where a required select must be non-empty. Set to false for custom validation.
validbooleanWhether or not the component is in a valid state. Setting this updates styles on the component, but does not affect the native validity state.
requiredbooleanWhether or not the component is required. Setting this updates the required or aria-required attribute on the component and enables validation.
leadingIconAriaLabelstring (write-only)Proxies to the foundation's setLeadingIconAriaLabel method.
leadingIconContentstring (write-only)Proxies to the foundation's setLeadingIconContent method.
helperTextContentstring (write-only)Proxies to the foundation's setHelperTextContent method when set.
rippleMDCRippleRipple instance attached to outlined select variant, or null for all other variants.
Method SignatureDescription
layout() => voidRe-calculates if the notched outline should be notched and if the label should float. Proxies to the foundation's layout() method.
layoutOptions() => voidSynchronizes the list of options with the state of the foundation. Proxies to the foundation's layoutOptions() method. Call this whenever menu options are dynamically updated.

Events

Event NameDataDescription
MDCSelect:change{value: string, index: number}Used to indicate when an element has been selected. This event also includes the value of the item and the index.

Usage within Web Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a Select for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.

MDCSelectAdapter

Method SignatureDescription
addClass(className: string) => voidAdds a class to the select element.
removeClass(className: string) => voidRemoves a class from the select element.
hasClass(className: string) => booleanReturns true if the select element has the className in its classList.
activateBottomLine() => voidActivates the bottom line component.
deactivateBottomLine() => voidDeactivates the bottom line component.
hasLabel() => booleanReturns true if the select contains a label.
floatLabel(value: boolean) => voidFloats or defloats label.
getLabelWidth() => numberReturns the offsetWidth of the label element.
hasOutline() => booleanReturns true if the select has the notched outline element.
notchOutline(labelWidth: number) => voidSwitches the notched outline element to its "notched state."
closeOutline() => voidSwitches the notched outline element to its closed state.
setDisabled(isDisabled: boolean) => voidEnables or disables the select.
openMenu() => voidOpens the menu and applies activated styling.
setRippleCenter(normalizedX: number) => voidSets the line ripple center to the provided normalizedX value.
notifyChange(value: string) => voidEmits the MDCSelect:change event when an element is selected.
setSelectedText(text: string) => voidSets the text content of the selectedText element to the given string.
isSelectAnchorFocused() => booleanReturns whether the select anchor element is focused.
getSelectAnchorAttr(attr: string) => stringGets the given attribute on the select anchor element.
setSelectAnchorAttr(attr: string, value: string) => voidSets the given attribute on the select anchor element.
removeSelectAnchorAttr(attr: string) => voidRemoves the given attribute on the select anchor element.
openMenu() => voidCauses the menu element in the select to open.
closeMenu() => voidCauses the menu element in the select to close.
getAnchorElement() => ElementReturns the select anchor element.
setMenuAnchorElement(anchorEl: Element) => voidSets the menu anchor element.
setMenuAnchorCorner(anchorCorner: Corner) => voidSets the menu anchor corner.
setMenuWrapFocus(wrapFocus: boolean) => voidSets whether the menu should wrap focus.
focusMenuItemAtIndex(index: number) => voidFocuses the menu item at the given index.
getMenuItemValues() => string[]Returns an array representing the VALUE_ATTR attributes of each menu item.
getMenuItemCount() => numberReturns the number of menu items.
getMenuItemTextAtIndex(index: number) => stringGets the text content of the menu item element at the given index.
getSelectedIndex() => numberReturns the selected index in the menu.
setSelectedIndex() => numberSets the selected index in the menu.
isTypeaheadInProgress() => booleanReturns whether typeahead is in progress in the menu.
typeaheadMatchItem: (nextChar: string, startingIndex: number) => numberAdds a character to the list typeahead buffer and returns index of the next item in the list matching the buffer.

MDCSelectFoundation

Method SignatureDescription
notchOutline(openNotch: boolean) => voidOpens/closes the notched outline.
getDisabled() => booleanGets the disabled state.
setDisabled(isDisabled: boolean) => voidUpdates the disabled state.
handleFocus() => voidHandles a focus event on the select element.
handleBlur() => voidHandles a blur event on the select element.
handleClick(normalizedX: number) => voidSets the line ripple center to the normalizedX for the line ripple.
handleMenuOpened() => voidHandles menu or menu surface opened event.
handleMenuClosed() => voidHandles menu or menu surface closed event.
handleMenuItemAction() => voidHandles menu selected event.
handleChange() => voidHandles a change to the select element's value. This must be called both for change events and programmatic changes requested via the component API.
handleKeydown(event: KeyboardEvent) => voidHandles opening the menu when the mdc-select__selected-text element is focused and the user presses the Enter or Space key.
getSelectedIndex() => numberReturns the index of the currently selected menu item.
setSelectedIndex(index: number) => voidHandles setting the mdc-select__selected-text element and closing the menu. Also causes the label to float and outline to notch if needed.
getValue() => stringHandles getting the value through the adapter.
setValue() => stringSets the selected index to the index of the menu item with the given value.
setUseDefaultValidation(useDefaultValidation: boolean) => voidEnables or disables the default validation scheme where a required select must be non-empty. Set to false for custom validation.
setValid(isValid: boolean) => voidSets the valid state through the adapter. Note that default validation scheme where a required select is invalid if empty will still be honored subsequently unless setUseDefaultValidation(false) is also called.
isValid() => booleanGets the valid state through the adapter's checkValidity API.
setRequired(isRequired: boolean) => voidSets the required state through the adapter.
getRequired() => booleanGets the required state through the adapter.
init() => voidInitializes the foundation.
layout() => voidRe-calculates if the notched outline should be notched and if the label should float.
layoutOptions() => voidSynchronizes the list of options with the state of the foundation. Call this whenever menu options are dynamically updated.
setLeadingIconAriaLabel(label: string) => voidSets the aria label of the leading icon.
setLeadingIconContent(content: string) => voidSets the text content of the leading icon.
setHelperTextContent(content: string) => voidSets the content of the helper text.

MDCSelectFoundation supports multiple optional sub-elements: helper text and icon. The foundations of these sub-elements must be passed in as constructor arguments to MDCSelectFoundation.

Keywords

FAQs

Package last updated on 28 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc