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

@rmwc/select

Package Overview
Dependencies
Maintainers
1
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rmwc/select

RMWC Select component

  • 2.0.0-alpha.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.3K
decreased by-32.52%
Maintainers
1
Weekly downloads
 
Created
Source

Select Menus

Menus display a list of choices on a transient sheet of material.

  • import * from '@rmwc/select';
  • import styles:
    • import '@material/select/dist/mdc.select.css';
  • MDC Docs: https://material.io/develop/web/components/input-controls/select-menus/

Select Styles

Selects come in three different styles: standard, box, and outlined.

<Select
  label="Standard"
  placeholder=""
  options={['Cookies', 'Pizza', 'Icecream']}
/>

<Select
  label="Boxed"
  box
  placeholder=""
  options={['Cookies', 'Pizza', 'Icecream']}
/>

<Select
  label="Outlined"
  outlined
  placeholder=""
  options={['Cookies', 'Pizza', 'Icecream']}
/>

Data Driven Selects

To fit common use cases, RMWC Select provides a data driven method for rendering select menus. There are multiple formats you can pass data in, use the one that best fits your requirements. To make your label not float by default and to have an unselected blank value, set the placeholder prop to a blank string.

import { Select } from '@rmwc/select';

{/*
  A controlled select
  Using a formatted array of options
  [
    {label: string, value: string, ...props},
    {label: string, value: string, ...props}
  ]
*/}

<Select
  value={this.state.value}
  onChange={evt => this.setState({value: evt.target.value})}
  label="Array"
  placeholder=""
  options={[
    {
      label: 'Cookies',
      value: '1'
    },
    {
      label: 'Pizza',
      value: '2',

      /** Any additional items will be passed to the
       child ListItem as props */

      'aria-disabled': true,
      'tabIndex': -1
    },
    {
      label: 'Icecream',
      value: '3'
    }
  ]}
/>

{/*  
  An uncontrolled select
  A simple value => label map */
}
<Select
  label="Object map"
  options={{'1': 'Cookies', '2': 'Pizza', '3': 'Icecream'}}
/>

{/* a simple array of options with box styling, value will be the same as label */}
<Select
  label="Simple Array"
  placeholder="-- Select One --"
  options={['Cookies', 'Pizza', 'Icecream']}
/>

Manually building the list

If you want full control over the child ListItems, you can manually build the list yourself.

import { Select } from '@rmwc/select';

<Select
  label="Manual"
  defaultValue=""
>
  <option value="" disabled></option>
  <option value="Cookies">
    Cookies
  </option>
  <option value="Pizza">
    Pizza
  </option>
  <option value="Icecream">
    Icecream
  </option>
</Select>

Option Groups

You can build a select with optgroup.

import { Select } from '@rmwc/select';

<Select
  label="Formatted"
  options={[
    {
      label: 'Dinner',
      options: [
        {
          label: 'Pizza',
          value: '2',
        }
      ]
    },
    {
      label: 'Dessert',
      options: [
        {
          label: 'Cookies',
          value: '1'
        },

        {
          label: 'Icecream',
          value: '3'
        }
      ]
    }
  ]}
/>

<Select
  label="Manually Built"
>
  <optgroup label="Dinner">
    <option value="Pizza">
      Pizza
    </option>
  </optgroup>
  <optgroup label="Dessert">
    <option value="Cookies">
      Cookies
    </option>
    <option value="Icecream">
      Icecream
    </option>
  </optgroup>
</Select>
import { DocumentComponent } from '@rmwc/base/utils/DocumentComponent';
import * as docs from './docgen.json';

<DocumentComponent docs={docs} displayName="Select" />

Keywords

FAQs

Package last updated on 07 Sep 2018

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