{"id":16690568,"url":"https://github.com/rusinovanton/react-select3","last_synced_at":"2025-04-10T00:51:09.057Z","repository":{"id":57344446,"uuid":"79742696","full_name":"RusinovAnton/react-select3","owner":"RusinovAnton","description":"This is \u003cselect\u003e written with ReactJS.","archived":false,"fork":false,"pushed_at":"2017-12-17T19:36:29.000Z","size":1880,"stargazers_count":6,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T00:51:02.342Z","etag":null,"topics":["es6","jest","npm-scripts","react","react-component","rollup","select","select2","selectbox"],"latest_commit_sha":null,"homepage":"https://rusinovanton.github.io/react-select3/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RusinovAnton.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-22T20:14:00.000Z","updated_at":"2023-08-01T19:40:50.000Z","dependencies_parsed_at":"2022-08-31T03:24:58.660Z","dependency_job_id":null,"html_url":"https://github.com/RusinovAnton/react-select3","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RusinovAnton%2Freact-select3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RusinovAnton%2Freact-select3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RusinovAnton%2Freact-select3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RusinovAnton%2Freact-select3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RusinovAnton","download_url":"https://codeload.github.com/RusinovAnton/react-select3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137997,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es6","jest","npm-scripts","react","react-component","rollup","select","select2","selectbox"],"created_at":"2024-10-12T16:04:17.947Z","updated_at":"2025-04-10T00:51:09.034Z","avatar_url":"https://github.com/RusinovAnton.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REACT-SELECT3\n\n[![npm](https://img.shields.io/npm/dm/localeval.svg)](https://www.npmjs.com/package/react-select3)\n[![Build Status](https://travis-ci.org/RusinovAnton/react-select3.svg?branch=master)](https://travis-ci.org/RusinovAnton/react-select3)\n\nThis is `\u003cselect\u003e` written with ReactJS.\n\n## Motivation:\n\n* Easy styling\n* Easy control\n* Easy fetching\n\n## [Demo](https://rusinovanton.github.io/react-select3/)\n\n## API reference\n\n### Select\n\nBasic usage:\n\n```javascript\nimport Select from 'react-select3'\nimport 'react-select3/dist/styles.css'\n\nconst selectOptions = [\n    { id: 1, text: 'Uno' },\n    { id: 2, text: 'Dos' },\n    { id: 3, text: 'Tres' },\n    { id: 4, text: 'Cuatro' },\n]\n\n\u003cSelect options={ selectOptions } placeholder={'Select option'}/\u003e\n```\n\nProps:\n\n| PropName                              | PropType              | Description                                                                                                     |\n| ------------------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------- |\n| **_allowClear_**                      | `\u003cbool\u003e`              | whether to allow user to clear selected option _`// Default: false`_                                            |\n| **_cssClassNamePrefix_**              | `\u003cstring\u003e`            | you can provide custom prefix for Selects' classNames                                                           |\n| **_autoFocus_**                       | `\u003cbool\u003e`              | whether to focus Select on mount                                                                                |\n| **_closeOnClickOutside_**             | `\u003cbool\u003e`              | whether to close dropdown on click outside Select component _`// Default: true`_                                |\n| **_defaultValue_**                    | `\u003cstring\u003e`/`\u003cnumber\u003e` | provide id of the default selected option                                                                       |\n| **_disabled_**                        | `\u003cbool\u003e`              | disable selecting and reseting                                                                                  |\n| **_error_**                           | `\u003cbool\u003e`/`\u003cstring\u003e`   | you can provide boolean to indicate Select's error or string to show error message                              |\n| **_layout_**                          | `\u003cobject\u003e`            | props related to Select component view                                                                          |\n| **_layout.width_**                    | `\u003cstring\u003e`            | width for Select container _`// Default: '245px'`_                                                              |\n| **_layout.dropdownVerticalPosition_** | 'above'/ 'below'      | whether to show dropdown above or below Select container _`// Default: 'below'`_                                |\n| **_layout.emptyOptionsLabel_**        | `\u003cstring\u003e`            | label that shows up when there is no options left                                                               |\n| **_name_**                            | `\u003cstring\u003e`            | Selects name attribute                                                                                          |\n| **_optionRenderer_**                  | `\u003cfunction\u003e`          | function that transforms single option output, you can provide it if you want to change layout of options e.g.: |\n|                                       |\n\n```javascript\nconst optionRenderer = option =\u003e (\n  \u003cstrong className=\"my-custom-option\"\u003e\n    \u003ci className={`fa fa-${icons[option.id]}`} /\u003e\n    {option.text}\n  \u003c/strong\u003e\n);\n```\n\n| PropName       | PropType     | Description                                                                                            |\n| -------------- | ------------ | ------------------------------------------------------------------------------------------------------ |\n| **_options_**  | `\u003carray\u003e`    | array with options object. they must have next format: `{ id: \u003cnumber|string\u003e, text: \u003cnumber|string\u003e}` |\n| **_onSelect_** | `\u003cfunction\u003e` | callback on options select event. event object that passed into callback has next format:              |\n\n```javascript\n{\n  type: 'select',\n  isClear: \u003cbool\u003e, // indicates that value being cleared by onClearSelection\n  target: {\n    name: \u003cstring\u003e, // Selects' name attribute\n    option: \u003cobject\u003e, // selected option object\n    value: \u003cstring\u003e, // selected option id\n  }\n}\n```\n\n| PropName                    | PropType              | Description                                                                                                                             |\n| --------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |\n| **_placeholder_**           | `\u003cstring\u003e`            | shows up when there is no selected option                                                                                               |\n| **_search_**                | `\u003cobject\u003e`            | props related to SearchInput, which used to filter options list, you can override its behaviour by providing `onSearchTermChange` prop. |\n| **_search.minimumResults_** | `\u003cnumber\u003e`            | minimum number of results before show SearchInput                                                                                       |\n| **_search.show_**           | `\u003cbool\u003e`              | provide if you want to always show SearchInput                                                                                          |\n| **_search.status_**         | `\u003cstring\u003e`            | provide status message, shows up only when there are no available options                                                               |\n| **_onSearchTermChange_**    | `\u003cfunction\u003e`          | callback for SearchInput changes, takes input event as agrument                                                                         |\n| **_value_**                 | `\u003cnumber\u003e`/`\u003cstring\u003e` | you can provide option id to control selection                                                                                          |\n\n### Selects ref interface methods\n\nSelect component has number of handy public methods that you can use by saving its ref, e.g.:\n\n```javascript\nclass MyMajesticComponent extends React.Component {\n  _selectRef = node =\u003e {\n    this.select = node;\n  };\n\n  _resetSelect = () =\u003e {\n    this.select.clear();\n  };\n\n  render = () =\u003e {\n    return (\n      \u003cdiv\u003e\n        \u003cSelect ref={this._selectRef} /\u003e\n        \u003cbutton onClick={this._resetSelect}\u003eReset\u003c/button\u003e\n      \u003c/div\u003e\n    );\n  };\n}\n```\n\nMethods:\n\n| Method name   | Method type | Description                                                                                                                                                                        |\n| ------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| **_clear_**   |             | use it to clear selection programmaticaly                                                                                                                                          |\n| **_options_** | `\u003csetter\u003e`  | sets options for Select component. `Select.options = [/* new options */]`. This setter is used by `FetchSelect` to set fetched options to Select component without rerendering it. |\n| **_options_** | `\u003cgetter\u003e`  | returns array of actual options from Selects' state `Select.options // options array`                                                                                              |\n| **_value_**   |             | returns id of currently selected option `Select.value // selected option's id`                                                                                                     |\n\n### FetchSelect\n\nThis component is a wrapper for Select component  \nthat provides interface for fetching options from server by \"termQuery\"  \non SearchInput change event, or once at component mount.\n\nUsage:\n\n```javascript\nimport { FetchSelect as Select } from 'react-select3'\nimport 'react-select3/dist/styles.css'\n\n// function that formats fetched objects into options\nconst responseDataFormatter = user =\u003e ({\n    // required keys\n    id: user._id,\n    text: `${user.first_name} ${user.last_name}`,\n\n    // Additional info that you can display in the options layout with \"optionRenderer\" function\n    phone: user.phone,\n    email: user.email,\n})\n\n// By default FetchSelect uses its own client that based on fetch,  \n// also you can provide your custom 'ajaxClient'  \n// e.g. endpoint: '/api/users/?filter=John\u0026emailVerified=0'  \nconst ajaxClient = (endpoint) =\u003e fetch(endpoint).then(data =\u003e data.users)\n\n\u003cSelect fetch={{\n            endpoint: '/api/users',\n            termQuery: 'filter',\n            responseDataFormatter,\n            ajaxClient,\n            params: { emailVerified: 0 }\n        }}\n        placeholder='Select user by typing his name'/\u003e\n```\n\nAll ref interface methods and props except of  \n`search.show`, `search.status` and `search.minimumResults`(if fetch.once = false)  \nare being proxied onto Select component.\n\nThere are a number of FetchSelect specific props:\n\n| PropName               | PropType     | Description                                                                                                                                        |\n| ---------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------- |\n| **_fetch_**            | `\u003cobject\u003e`   | props that related to fetching options from server                                                                                                 |\n| **_fetch.ajaxClient_** | `\u003cfunction\u003e` | custom client to fetch options, it must return `\u003cPromise\u003e`                                                                                         |\n| **_fetch.endpoint_**   | `\u003cstring\u003e`   | path to resource to fetch                                                                                                                          |\n| **_fetch.minLength_**  | `\u003cnumber\u003e`   | minimum characters length of SearchInput value to start fetching _`// Default: 3`_                                                                 |\n| **_fetch.once_**       | `\u003cbool\u003e`     | if true, options fetched once on FetchSelect mount, in this case SearchInput change not triggers fetch again but filters options that are in state |\n| **_fetch.params_**     | `\u003cobject\u003e`   | additional params that being merged with \"termQuery\" into endpoint e.g.                                                                            |\n\n```javascript\nSearchInput.value = 'John';\n\nfetch = {\n  endpoint: '/api/users',\n  termQuery: 'filter',\n  params: {\n    emailVerified: 0,\n  },\n};\n\n// fetch path: '/api/users?filter=John\u0026emailVerified=0'\n```\n\n| PropName                          | PropType     | Description                                                                           |\n| --------------------------------- | ------------ | ------------------------------------------------------------------------------------- |\n| **_fetch.requestDelay_**          | `\u003cnumber\u003e`   | delay between request on SearchInput change _`// Default: 300`_                       |\n| **_fetch.responseDataFormatter_** | `\u003cfunction\u003e` | function that formats fetched objects into options. See example above                 |\n| **_fetch.termQuery_**             | `\u003cstring\u003e`   | key for dynamic query param that takes SearchInput value on change. See example above |\n| **_language_**                    | `\u003cobject\u003e`   | pass language object to override default status labels:                               |\n\n```javascript\n{\n  isEmpty: 'No options.',\n  isPending: '...',\n  minLength: 'Minimum ${minLength} to search...',\n  responseEmpty: 'Cannot find anything.',\n  serverError: 'Server error.',\n}\n```\n\n### Styling\n\nYou can style Select component in a several ways:\n\n* Use default Select component styles by importing them from dist folder(TODO: skins):  \n  `import 'react-select3/dist/styles.css'`\n* Use scss source from `react-select3/src/styles/...`, override specific variables and mixins  \n  and compile into custom style\n* Write your own styles from scratch, you can even provide custom cssClassNamePrefix by passing prop  \n  into Select component and change variable in the scss source code\n\n## License\n\nreact-select3 Copyright 2017 Rusinov Anton\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n## Changelog\n\n[Changelog](https://github.com/RusinovAnton/react-select3/releases)\n\n### Credits\n\n⭐️ Thanks for help to:\n\n* Artem Berdyshev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusinovanton%2Freact-select3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusinovanton%2Freact-select3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusinovanton%2Freact-select3/lists"}