Socket
Socket
Sign inDemoInstall

@commercetools-uikit/selectable-search-input

Package Overview
Dependencies
115
Maintainers
3
Versions
250
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @commercetools-uikit/selectable-search-input

A controlled selectable search input component for single-line strings with validation states.


Version published
Weekly downloads
3.8K
increased by115.31%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

SelectableSearchInput

Description

A controlled selectable search input component for single-line strings with validation states.

Installation

yarn add @commercetools-uikit/selectable-search-input
npm --save install @commercetools-uikit/selectable-search-input

Additionally install the peer dependencies (if not present)

yarn add react react-dom react-intl
npm --save install react react-dom react-intl

Usage

import SelectableSearchInput from '@commercetools-uikit/selectable-search-input';

const value = {
  text: 'foo',
  option: 'bar',
};

const Example = () => (
  <SelectableSearchInput
    value={value}
    onChange={(event) => alert(event.target.value)}
    onSubmit={(val) => alert(val)}
    onReset={() => alert('reset')}
    options={[
      { value: 'one', label: 'One' },
      { value: 'two', label: 'Two' },
    ]}
    selectDataProps={[{ 'prop-1': 'value-1' }, { 'prop-2': 'value-2' }]}
    inputDataProps={[{ 'prop-3': 'value-1' }, { 'prop-4': 'value-2' }]}
  />
);

export default Example;

Properties

PropsTypeRequiredDefaultDescription
idstringUsed as HTML id property. An id is auto-generated when it is not specified.
autoCompletestringUsed as HTML autocomplete property
aria-invalidbooleanIndicate if the value entered in the input is invalid.
aria-errormessagestringHTML ID of an element containing an error message related to the input.
namestringUsed as HTML name of the input component property.
valueObject
See signature.
Value of the input. Consists of text input and selected option.
onChangeFunction
See signature.
Called with the event of the input or dropdown when either the selectable dropdown or the text input have changed. The change event from the text input has a suffix of .textInput and the change event from the dropdown has a suffix of .dropdown.
onBlurFunction
See signature.
Called when input is blurred
onFocusFunction
See signature.
Called when input is focused
onSubmitFunction
See signature.
Handler when the search button is clicked.
onResetFunction
See signature.
Handler when the clear button is clicked.
isAutofocussedbooleanFocus the input on initial render
isDisabledbooleanIndicates that the input cannot be modified (e.g not authorized, or changes currently saving).
isReadOnlybooleanIndicates that the field is displaying read-only content
hasErrorbooleanIndicates if the input has invalid values
hasWarningbooleanIndicates if the input has warning values
placeholderstringPlaceholder text for the input
isClearablebooleantrueIndicates if the input should be cleared when the clear button is clicked. Defaults to true.
horizontalConstraintunion
Possible values:
10 , 11 , 12 , 13 , 14 , 15 , 16 , 'scale' , 'auto'
'scale'Horizontal size limit of the input fields.
optionsunion
Possible values:
TOption[] , TOptionObject[]
[]Array of options that populate the select menu
menuPortalZIndexnumber1z-index value for the menu portal
Use in conjunction with menuPortalTarget
menuPortalTargetReactSelectProps['menuPortalTarget']Dom element to portal the select menu to
Props from React select was used
menuShouldBlockScrollReactSelectProps['menuShouldBlockScroll']whether the menu should block scroll while open
Props from React select was used
onMenuInputChangeReactSelectProps['onInputChange']Handle change events on the menu input
Props from React select was used
noMenuOptionsMessageReactSelectProps['noOptionsMessage']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.
Props from React select was used
isMenuSearchableReactSelectProps['isSearchable']Whether to enable search functionality.
Props from React select was used
maxMenuHeightReactSelectProps['maxMenuHeight']Maximum height of the menu before scrolling
Props from React select was used
closeMenuOnSelectReactSelectProps['closeMenuOnSelect']Whether the menu should close after a value is selected. Defaults to true.
Props from React select was used
menuHorizontalConstraintunion
Possible values:
3 , 4 , 5
3Horizontal size limit for the dropdown menu.
showSubmitButtonbooleantrueShow submit button in the input
selectDataPropsRecordused to pass data-* props to the select component. eg: selectDataProps={[{ 'prop-1': 'value-1' }, { 'prop-2': 'value-2' }]}
inputDataPropsRecordused to pass data-* props to the input element. eg: inputDataProps={[{ 'prop-1': 'value-1' }, { 'prop-2': 'value-2' }]}

Signatures

Signature value

{
  text: string;
  option: string;
}

Signature onChange

(event: TCustomEvent) => void

Signature onBlur

(event: TCustomEvent) => void

Signature onFocus

(event: TCustomEvent) => void

Signature onSubmit

(value: TValue) => void

Signature onReset

() => void

data-* props

The component further forwards all data- attributes to the underlying input component.

Static methods

SelectableSearchInput.isEmpty

Returns true when the value is considered empty, which is when the value is empty or consists of spaces only.

SelectableSearchInput.isEmpty({
  text: '',
  option: '',
}); // -> true
SelectableSearchInput.isEmpty({
  text: '    ',
  option: 'bar',
}); // -> true
SelectableSearchInput.isEmpty({
  text: 'foo',
  option: 'bar',
}); // -> false

Main Functions and use cases are:

  • Input field for single-line strings. Used for selectable search.

Keywords

FAQs

Last updated on 17 Apr 2024

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