{"name":"svelte-select","version":"4.4.4-beta.1","repository":{"type":"git","url":"git+https://rob-balfre@github.com/rob-balfre/svelte-select.git"},"description":"A <Select> component for Svelte apps","svelte":"src/index.js","module":"dist/index.mjs","main":"dist/index.js","types":"./src/index.d.ts","scripts":{"build":"rollup -c","dev":"rollup -cw","prepublishOnly":"npm run build","test":"node test/runner.js","test:browser":"npm run build && serve test/public","test:playwright":"playwright test","gen:docs":"node docs/generate_theming_variables_md.js","pretest":"npm run build"},"devDependencies":{"@babel/polyfill":"7.12.1","@playwright/test":"1.12.3","find-in-files":"^0.5.0","playwright-chromium":"1.12.3","port-authority":"^1.0.5","puppeteer":"^1.9.0","rollup":"^2.41.2","rollup-plugin-cleaner":"^1.0.0","rollup-plugin-css-only":"^3.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-serve":"1.1.0","rollup-plugin-svelte":"^7.1.0","rollup-plugin-terser":"^7.0.2","sirv":"^0.2.2","svelte":"^3.38.3","tap-diff":"^0.1.1","tap-dot":"^2.0.0","tape-modern":"^1.1.1"},"author":{"name":"rob-balfre"},"license":"LIL","keywords":["svelte"],"readme":"# svelte-select\n\nA select/autocomplete component for Svelte apps.  With support for grouping, filtering, async and more.\n\n## Demos\n\n🌱 [Simple demo](https://svelte.dev/repl/a859c2ba7d1744af9c95037c48989193?version=3.12.1)\n\n🌻 [Advanced demo](https://svelte.dev/repl/3e032a58c3974d07b7818c0f817a06a3?version=3.20.1)\n\n## Installation\n\n```bash\nyarn add svelte-select\n```\n\n**Note:** Install as a dev dependency (yarn add svelte-select --dev) if using [Sapper](https://sapper.svelte.dev/) to avoid a SSR error.\n\n\n## Usage\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let items = [\n    {value: 'chocolate', label: 'Chocolate'},\n    {value: 'pizza', label: 'Pizza'},\n    {value: 'cake', label: 'Cake'},\n    {value: 'chips', label: 'Chips'},\n    {value: 'ice-cream', label: 'Ice Cream'},\n  ];\n\n  let value = {value: 'cake', label: 'Cake'};\n\n  function handleSelect(event) {\n    console.log('selected item', event.detail);\n    // .. do something here 🙂\n  }\n</script>\n\n<Select {items} {value} on:select={handleSelect}></Select>\n```\n\n## API\n\n- `id: String` Default: `null`. Add an id to the input field.\n- `items: Array` Default: `[]`. List of selectable items that appear in the dropdown.\n- `value: Any` Default: `null`. Selected item or items.\n- `filterText: String` Default: `''`. Text to filter `items` by.\n- `placeholder: String` Default: `'Select...'`. Placeholder text.\n- `noOptionsMessage: String` Default: `'No options'`. Message to display in list when there are no `items`.\n- `optionIdentifier: String` Default: `'value'`. Override default identifier.\n- `labelIdentifier: String` Default: `'label'`. Override default identifier.\n- `listOpen: Boolean` Default: `false`. Open/close list.\n- `hideEmptyState: Boolean` Default: `false`. Hide list and don't show `noOptionsMessage` when there are no `items`.\n- `containerClasses: String` Default: `''`. Add extra container classes, for example 'global-x local-y'.\n- `containerStyles: String` Default: `''`. Add inline styles to container.\n- `isClearable: Boolean` Default: `true`. Enable clearing of selected items.\n- `isCreatable: Boolean` Default: `false`. Can create new item(s) to be added to `value`.\n- `isDisabled: Boolean` Default: `false`. Disable select.\n- `isMulti: Boolean` Default: `false`. Enable multi-select, `value` becomes an array of selected items.\n- `isSearchable: Boolean` Default: `true`. Enable search/filtering of `items` via `filterText`.\n- `isGroupHeaderSelectable: Boolean` Default: `false`. Enable selectable group headers in `items` (see adv demo).\n- `listPlacement: String` Default: `'auto'`. When `'auto'` displays either `'top'` or `'bottom'` depending on viewport.\n- `hasError: Boolean` Default: `false`. Show/hide error styles around select input (red border by default).\n- `listAutoWidth: Boolean` Default: `true`. List width will grow wider than the Select container (depending on list item content length).\n- `showIndicator: Boolean` Default: `false`. If true, the chevron indicator is always shown.\n- `inputAttributes: Object` Default: `{}`. Pass in HTML attributes to the Select input.\n- `Item: Component` Default: `Item`. Item component.\n- `Selection: Component` Default: `Selection`. Selection component.\n- `MultiSelection: Component` Default: `MultiSelection`. Multi selection component.\n- `Icon: Component` Default: `Icon`. Icon component.\n- `iconProps: Object` Default: `{}`. Icon props.\n- `indicatorSvg: @html` Default: `undefined`. Override default SVG chevron indicator.\n- `ClearIcon` Default: `ClearIcon`. ClearIcon component.\n- `isVirtualList: Boolean` Default: `false`. Uses [svelte-virtual-list](https://github.com/sveltejs/svelte-virtual-list) to render list (experimental).\n- `filteredItems: Array` Default: `[]`. List of items that are filtered by `filterText`\n- `placeholderAlwaysShow: Boolean` Default: `false`. When `isMulti` then placeholder text will always still show.\n- `isWaiting: Boolean` Default: `false`. If true then loader shows. `loadOptions` will automatically set this as true until promise resolves.\n- `listOffset: Number` Default: `5`. Controls the spacing offset between the list and the input.\n\n### Items\n\n`items` can be simple arrays or collections.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let simple = ['one', 'two', 'three'];\n\n  let collection = [\n    { value: 1, label: 'one' },\n    { value: 2, label: 'two' },\n    { value: 3, label: 'three' },\n  ];\n</script>\n\n<Select items={simple} />\n\n<Select items={collection} />\n```\n\nThey can also be grouped and include non-selectable items.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = [\n    {value: 'chocolate', label: 'Chocolate', group: 'Sweet'},\n    {value: 'pizza', label: 'Pizza', group: 'Savory'},\n    {value: 'cake', label: 'Cake', group: 'Sweet', selectable: false},\n    {value: 'chips', label: 'Chips', group: 'Savory'},\n    {value: 'ice-cream', label: 'Ice Cream', group: 'Sweet'}\n  ];\n\n  const groupBy = (item) => item.group;\n</script>\n\n<Select {items} {groupBy} />\n\n```\n\nYou can also use custom collections.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const optionIdentifier = 'id';\n  const labelIdentifier = 'title';\n\n  const items = [\n    {id: 0, title: 'Foo'},\n    {id: 1, title: 'Bar'},\n  ];\n</script>\n\n<Select {optionIdentifier} {labelIdentifier} {items} />\n```\n\n### Async Items\n\nTo load items asynchronously then `loadOptions` is the simplest solution. Supply a function that returns a `Promise` that resolves with a list of items. `loadOptions` has debounce baked in and fires each time `filterText` is updated.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  import { someApiCall } from './services';\n\n  async function examplePromise(filterText) {\n    // Put your async code here...\n    // For example call an API using filterText as your search params\n    // When your API responds resolve your Promise\n    let res = await someApiCall(filterText);\n    return res;\n  }\n</script>\n\n<Select loadOptions={examplePromise} />\n```\n\n### Exposed methods\nThese internal functions are exposed to override if needed. See the adv demo or look through the test file (test/src/index.js) for examples.\n\n```js\nexport let itemFilter = (label, filterText, option) => label.toLowerCase().includes(filterText.toLowerCase());\n```\n\n```js\nexport let groupBy = undefined;\n```\n\n```js\nexport let groupFilter = groups => groups;\n```\n\n```js\nexport let createGroupHeaderItem = groupValue => {\n  return {\n    value: groupValue,\n    label: groupValue\n  };\n};\n```\n\n```js\nexport let createItem = filterText => {\n  return {\n    value: filterText,\n    label: filterText\n  };\n};\n```\n\n```js\nexport let getOptionLabel = (option, filterText) => {\n  return option.isCreator ? `Create \\\"${filterText}\\\"` : option.label;\n};\n```\n\n```js\nexport let getSelectionLabel = option => {\n  if (option) return option.label;\n};\n```\n\n```js\nexport let getGroupHeaderLabel = option => {\n  return option.label;\n};\n```\n\n```js\nexport function handleClear() {\n  value = undefined;\n  listOpen = false;\n  dispatch(\"clear\", value);\n  handleFocus();\n}\n```\n\n```js\nexport let loadOptions = undefined; // if used must return a Promise that updates 'items'\n/* Return an object with { cancelled: true } to keep the loading state as active. */\n```\n\n```js\nexport const getFilteredItems = () => {\n  return filteredItems;\n};\n```\n\n## A11y (Accessibility)\n\nOverride these methods to change the `aria-context` and `aria-selection` text.\n\n```js\nexport let ariaValues = (values) => {\n  return `Option ${values}, selected.`;\n}\n\nexport let ariaListOpen = (label, count) => {\n  return `You are currently focused on option ${label}. There are ${count} results available.`;\n}\n\nexport let ariaFocused = () => {\n  return `Select is focused, type to refine list, press down to open the menu.`;\n}\n```\n\n## Styling\n\nYou can style a component by overriding [the available CSS variables](/docs/theming_variables.md).\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = ['One', 'Two', 'Three'];\n</script>\n\n<style>\n  .themed {\n    --border: 3px solid blue;\n    --borderRadius: 10px;\n    --placeholderColor: blue;\n  }\n</style>\n\n<div class=\"themed\">\n  <h2>Theming</h2>\n  <Select {items}></Select>\n</div>\n```\n\nYou can also use the `inputStyles` prop to write in any override styles needed for the input.\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  const items = ['One', 'Two', 'Three'];\n</script>\n\n<Select {items} inputStyles=\"box-sizing: border-box;\"></Select>\n```\n\n## Events\n\n| Event Name | Callback | Description |\n|------|------|----------|\n| select | { detail } | fires when value changes\n| clear | { detail } | fires when clear all is invoked or item is removed (by user) from multi select\n| loaded | { items } | fires when `loadOptions` resolves\n| error | { type, details } | fires when error is caught\n\n```html\n<script>\n  import Select from 'svelte-select';\n\n  let items = [...];\n  function handleSelect(event) {\n    // event.detail will contain the selected value\n    ...\n  }\n  function handleClear(event) {\n    // event.detail will be null unless isMulti is true and user has removed a single item\n    ...\n  }\n</script>\n\n<Select {items} on:select={handleSelect} on:clear={handleClear}></Select>\n```\n\n## Development\n\n```bash\nyarn global add serve@8\nyarn\nyarn dev\nyarn test:browser\n```\n\nIn your favourite browser go to http://localhost:3000 and open devtools and see the console for the test output. When developing its handy to see the component on the page; comment out the `select.$destroy();` on the last test in /test/src/index.js or use the `test.only()` to target just one test.\n\nFor example:\n\n```js\ntest.only('when getSelectionLabel contains HTML then render the HTML', async (t) => {\n  const select = new Select({\n    target,\n    props: {\n      value: items[0],\n      getSelectionLabel: (option) => `<p>${option.label}</p>`,\n    }\n  });\n\n  t.ok(document.querySelector('.selection').innerHTML === '<p>Chocolate</p>');\n\n  //select.$destroy();\n});\n\n```\n\n\n## Configuring webpack\n\nIf you're using webpack with [svelte-loader](https://github.com/sveltejs/svelte-loader), make sure that you add `\"svelte\"` to [`resolve.mainFields`](https://webpack.js.org/configuration/resolve/#resolve-mainfields) in your webpack config. This ensures that webpack imports the uncompiled component — this is more efficient.\n\nIf you're using Rollup with [rollup-plugin-svelte](https://github.com/rollup/rollup-plugin-svelte), this will happen automatically.\n\n\n## License\n\n[LIL](LICENSE)\n","readmeFilename":"README.md","gitHead":"c51e9dee55cba54ef761b6caef13af7e7d1fb025","bugs":{"url":"https://github.com/rob-balfre/svelte-select/issues"},"homepage":"https://github.com/rob-balfre/svelte-select#readme","_id":"svelte-select@4.4.4-beta.1","_nodeVersion":"16.2.0","_npmVersion":"7.13.0","dist":{"integrity":"sha512-uIm1Xh0uzTLqQED05sha8fmrVEd2Q8W5EXDuTFZf/2FIaJWC+nOsOVAgd0jMFzaoywSfsC6OsHKFagc5Pf457w==","shasum":"dfa56a6883df7e55ee69498644d553c755aa0b92","tarball":"http://registry-npm.ywwl.com/svelte-select/download/svelte-select-4.4.4-beta.1.tgz","fileCount":17,"unpackedSize":167902,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIH+xA4htFvdcHCbyYwMhGB5HBhySvckBeaV+zN2sdS1zAiBMNvscq2XbBFOCilF3HeQkzPqaMAjNFbXGsBsYHvguJA=="}],"size":49715,"noattachment":false,"key":"/svelte-select/-/svelte-select-4.4.4-beta.1.tgz"},"_npmUser":{"name":"rob-balfre","email":"rob.balfre@gmail.com"},"directories":{},"maintainers":[{"name":"rob-balfre","email":"rob.balfre@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/svelte-select_4.4.4-beta.1_1636583893136_0.17072315021196793"},"_hasShrinkwrap":false,"publish_time":1636583893303,"_cnpm_publish_time":1636583893303,"dist-tags":{"alpha":"5.0.0-alpha.10","beta":"5.3.0-beta.7","latest":"6.0.0"}}