Socket
Socket
Sign inDemoInstall

@paprika/select

Package Overview
Dependencies
93
Maintainers
3
Versions
105
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @paprika/select

The Select component is a styled select drop-down form input that can be used as a controlled or uncontrolled component.


Version published
Weekly downloads
2.6K
decreased by-0.57%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

@paprika/select

Description

The Select component is a styled select drop-down form input that can be used as a controlled or uncontrolled component.

Installation

yarn add @paprika/select

or with npm:

npm install @paprika/select

Props

Select

PropTyperequireddefaultDescription
a11yTextstringfalsenullProvides a non-visible label for this select element for assistive technologies.
childrennodefalsenullList of options as standard option elements.
defaultValuestringfalsenullSets the default selected value for an uncontrolled component.
hasErrorboolfalsefalseIf true displays a red border around select element to indicate error.
isDisabledboolfalsefalseIf true it makes the select element disabled.
isReadOnlyboolfalsefalseIf true it makes the select element read only.
onChangefuncfalse() => {}Callback to be executed when the selected value is changed. Receives the onChange event as an argument. Required when value prop is provided (component is controlled).
placeholderstringfalsenullDisplay value for a disabled first option with an empty string value.
size[ Select.types.size.SMALL, Select.types.size.MEDIUM, Select.types.size.LARGE]falseSelect.types.size.MEDIUMSpecifies the visual size of the select element.
valuestringfalseundefinedThe selected value for the select element.

Select.Container

All props and attributes are spread onto the root container <div> element.

Usage

The <Select> can be used as a controlled or an uncontrolled component.

To use it as a controlled component:

import Select from "@paprika/select";
...
const [value, setValue] = React.useState("Coke");
...
<Select
  value={value}
  onChange={event => setValue(event.target.value)}
>
  <option value="Coke">Coke</option>
  <option value="Pepsi">Pepsi</option>
</Select>

To use it as an uncontrolled component:

import Select from "@paprika/select";
...
const refSelect = React.useRef();
...
<Select
  defaultValue="Coke"
  ref={refSelect}
>
  <option value="Coke">Coke</option>
  <option value="Pepsi">Pepsi</option>
</Select>
...
refSelect.current.value // latest value

To access the value of an uncontrolled component, you can pass a handler function for the onChange prop that will have the event as an argument. You can use the event.target.value as needed.

Alternatively, you can include a ref on the component and access ref.current.value at any time.

  • Storybook Showcase
  • GitHub source code
  • Create GitHub issue
  • CHANGELOG

FAQs

Last updated on 22 Apr 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc