2.1.0 • Published 2 years ago

artof-select v2.1.0

Weekly downloads
216
License
MIT
Repository
github
Last release
2 years ago

artof-select

NPM BUNDLEPHOBIA NPM

A simple, but powerful React Select component. Can be used for both Select Single React form element and Select Multiple React form element.

Key features:

  • Based on native HTMLSelectElement props and methods
  • Supports multiple selection
  • Supports searching through options list
  • Fully customisable design
  • Select provides display of hints and error notifications
  • Multiple selected options can be shown as [tag] [tag] [tag]
  • Supports native keyboard events, like Tab, Arrow Up | Down to navigate over the dropdown options and Enter (or even Spacebar) to apply selected option(s).
  • Supports custom React.ReactNode component as option element

In addition, this component works with @floating-ui/react-dom to make better dropdown positioning.

Demo Storybook here

Installation and usage

npm i artof-select

or

yarn add artof-select

As soon as it installed, you can easily use Select in your app:

import { Select } from 'artof-select';

// custom
import 'artof-select/dist/index.scss';

const App = () => {
  const [value, setValue] = useState();

  const handleChange = (event) => {
    setValue(event.currentTarget.value);
  }

  return (
    <Select
      label="Some label"
      value={value}
      options={[]}
      onChange={handleChange}
      allowSearch={true}
    />
  )
}

Props

Common props you may want to specify include:

PropsDefaultDescription
allowClearAllfalseAdd button to clear the selection
allowMarkWordstrueWrap keywords with <mark /> for allowSearch={true}
allowRemoveTagfalseAdd additional close icon for every tag, when asTags={true}
allowSearchfalseAllow the user to search for inside options
allowSelectAllfalseInclude Select All button with multiple options
allowTagsCountfalseAdd counter before selected tags, when asTags={true}
aria-expandedfalseIf true - can open the Dropdown on init
asTagsfalseUse with multiple={true} to display selections as tags
autoFocusundefinedDefault <select />'s attribute. Set focus when did mount
classNameundefinedAdditional className can be attached to the wrapper
datatypeundefinedPossibility to pass data-types attributes to <select/>
disabledundefinedDefault <select />'s attribute
dropdownOffset4Offset dropdown positioning
dropdownPositionbottom-startPosition for Dropdown, based on @floating-ui props
errorTextundefinedA text below the Select connected with classNames
formundefinedDefault <select />'s attribute
hintTextundefinedA text below the Select (and under the errorText)
idundefinedDefault <select />'s attribute
labelundefinedGenerates an label with this name above the Select
labelPositionbeforePosition for Label (beforeinsideafter)
multiplefalseAllow the user to select multiple values
nameundefinedDefault <select />'s attribute
onBlurundefinedHandle the Blur event
onFocusundefinedHandle the Focus event
onKeyDownundefinedHandle the KeyDown event
onKeyUpundefinedHandle the KeyUp event
onToggleundefinedTo handle th Dropdown open\close state
onSearchChangeundefinedHandle the SearchChange event
options[]Specify the options the user can select from
placeholderundefinedThe text displayed when no option is selected
renderValueundefinedA function, that can render custom selected value
requiredundefinedDefault <select />'s attribute
searchPositionvaluePosition for search field (valuedropdown)
searchPlaceholderundefinedA placeholder for search field (inside dropdown only)
splitterBefore0To set additional HTMLDivElement before an option item
styleundefinedDefault <select />'s attribute
textSelectAllSelect allA translation text Select All if allowSelectAll={true}
textSelectedSelectedA translation text Selected %n if multiple={true}
valueundefinedCurrent value. A string or an string[] if multiple={true}

Also, the onChange prop can return event: React.ChangeEvent<HTMLSelectElement> or values: string[] depend on multiple option.

In addition to above props, you can get access to the Select component with ref. This will allow you to force some events, like: selectRef.current?.focus()

Run the Demo from local

You can check out the demo:

git clone https://github.com/o-mega/artof-select.git
cd artof-select
npm install
npm run dev

This commands should run the Storybook with designed examples at http://localhost:6006

License

MIT Licensed. Copyright (c) Oleg Frolov

2.0.0

2 years ago

1.13.4

2 years ago

1.13.3

2 years ago

2.1.0

2 years ago

1.12.4

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.11.10

2 years ago

1.11.9

3 years ago

1.11.8

3 years ago

1.11.7

3 years ago

1.11.6

3 years ago

1.11.3

3 years ago

1.11.5

3 years ago

1.8.2

3 years ago

1.8.1

3 years ago

1.11.0

3 years ago

1.11.2

3 years ago

1.11.1

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.10.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.7

3 years ago

1.5.6

3 years ago

1.5.5

3 years ago

1.5.4

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.7

3 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.4.0

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago