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

@commercetools-uikit/async-select-input

Package Overview
Dependencies
Maintainers
3
Versions
1000
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercetools-uikit/async-select-input

## Description

  • 0.0.0-canary-2020717826
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
increased by16.43%
Maintainers
3
Weekly downloads
 
Created
Source

AsyncSelectInput

Description

An input component getting a selection from an asynchronously loaded list from the user.

Usage

import AsyncSelectInput from '@commercetools-uikit/async-select-input';

<AsyncSelectInput
  name="form-field-name"
  value={value}
  onChange={handleChange}
  options={[
    { value: 'one', label: 'One' },
    { value: 'two', label: 'Two' },
  ]}
/>;

Terminology

option

An option is a suggestion the user can select. The option minimally consists of:

{ label, value }

An option also has the special __isNew__ property, which gets added when the option was created by the user.

The options flow into AsyncSelectInput by either being passed as defaultOptions or by being returned from loadOptions. The parent finds out about selected options through onChange (which passes the selected option values up, including any addition information available on defaultOptions or returned from loadOptions).

value

There are two types of values:

  • the value of an option
  • the value of the AsyncSelectInput

value (of option)

Each option has a value. This is a plain-text string. The onChange method is passed the value of the selected option (or the selected options when in isMulti mode).

value (of AsyncSelectInput)

Any parent component using AsyncSelectInput has to pass in a value, which is is the selected option (or an array of selected options when in isMulti mode).

Properties

PropsTypeRequiredValuesDefaultDescription
horizontalConstraintobject-s, m, l, xl, scalescaleHorizontal size limit of the input fields.
hasErrorbool---Indicates the input field has an error
hasWarningbool---Indicates the input field has a warning
aria-labelstring---Aria label (for assistive tech)
aria-labelledbystring---HTML ID of an element that should be used as the label (for assistive tech)
isAutofocussedbool---Focus the control when it is mounted
backspaceRemovesValuebool--trueRemove the currently focused option when the user presses backspace
componentsobjectOf(func)---Map of components to overwrite the default ones, see what components you can override
filterOptionfunc---Custom method to filter whether an option should be displayed in the menu
idstring---The id of the search input
containerIdstring---The id to set on the SelectContainer component
isClearablebool---Is the select value clearable
isDisabledbool---Is the select disabled
isReadOnlybool---Is the select read-only
isOptionDisabledfunc---Override the built-in logic to detect whether an option is disabled
isMultibool---Support multiple selected options
isSearchablebool--trueWhether to enable search functionality
maxMenuHeightnumber---Maximum height of the menu before scrolling
menuPortalTargetHTMLElement---Dom element to portal the select menu to
menuPortalZIndexnumber---z-index value for the menu portal
menuShouldBlockScrollbool--falsewhether the menu should block scroll while open
namestring---Name of the HTML Input (optional - without this, no input will be rendered)
noOptionsMessagefunc---Can be used to render a custom value when there are no options (either because of no search results, or all options have been used, or there were none in the first place). Gets called with { inputValue: String }. inputValue will be an empty string when no search text is present.
onBlurfunc---Handle blur events on the control
onChangefunc--Called with a fake event when value changes. The event's target.name will be the name supplied in props. The event's target.value will hold the value. The value will be the selected option, or an array of options in case isMulti is true.
onFocusfunc---Handle focus events on the control
onInputChangefunc---Handle change events on the input
placeholderstring---Placeholder text for the select value
tabIndexstring--"0"Sets the tabIndex attribute on the input
tabSelectsValuebool--trueSelect the currently focused option when the user presses tab
valueobject / array---The value of the select; reflected by the selected option
defaultOptionsboolean / array---The default set of options to show before the user starts searching. When set to true, the results for loadOptions('') will be autoloaded.
loadOptionsfunction---Function that returns a promise, which is the set of options to be used once the promise resolves.
cacheOptionsany---If cacheOptions is truthy, then the loaded data will be cached. The cache will remain until cacheOptions changes value.
showOptionGroupDividerboolean--falseDetermines if option groups will be separated by a divider

This input is built on top of react-select v2. It supports mostly same properties as react-select. Behaviour for some props was changed, and support for others was dropped.

In case you need one of the currently excluded props, feel free to open a PR adding them.

Static Properties

isTouched(touched)

Expects to be called with an array or boolean. Returns true when truthy.

Components

It is possible to customize SelectInput by passing the components property. SelectInput exports the default underlying components as static exports.

Components available as static exports are:

  • ClearIndicator
  • Control
  • DropdownIndicator
  • DownChevron
  • CrossIcon
  • Group
  • GroupHeading
  • IndicatorsContainer
  • IndicatorSeparator
  • Input
  • LoadingIndicator
  • Menu
  • MenuList
  • MenuPortal
  • LoadingMessage
  • NoOptionsMessage
  • MultiValue
  • MultiValueContainer
  • MultiValueLabel
  • MultiValueRemove
  • Option
  • Placeholder
  • SelectContainer
  • SingleValue
  • ValueContainer

See the official documentation for more information about the props they receive.

FAQs

Package last updated on 17 Aug 2020

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