diff --git a/.all-contributorsrc b/.all-contributorsrc index 5e98bc5..c52f03e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -63,6 +63,17 @@ "test" ] }, + { + "login": "vivekitis", + "name": "Vivek Ashokan", + "avatar_url": "https://avatars2.githubusercontent.com/u/16322466?v=4", + "profile": "https://github.com/vivekitis", + "contributions": [ + "code", + "doc", + "example" + ] + }, { "login": "42tte", "name": "Kristoffer Nordström", diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html index 73a8d97..7236667 100644 --- a/.storybook/preview-head.html +++ b/.storybook/preview-head.html @@ -1,89 +1,91 @@ + #autosuggest__input.autosuggest__input--open { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + } + + .autosuggest__results-container { + position: relative; + width: 100%; + } + + .autosuggest__results { + font-weight: 300; + margin: 0; + position: absolute; + z-index: 10000001; + width: 100%; + border: 1px solid #e0e0e0; + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + background: white; + padding: 0px; + } + + .autosuggest__results ul { + list-style: none; + padding-left: 0; + margin: 0; + } + + .autosuggest__results .autosuggest__results-item { + cursor: pointer; + padding: 15px; + } + + #autosuggest ul:nth-child(1)>.autosuggest__results-before { + border-top: none; + } + + .autosuggest__results .autosuggest__results-before { + color: gray; + font-size: 11px; + margin-left: 0; + padding: 15px 13px 5px; + border-top: 1px solid lightgray; + } + + .autosuggest__results .autosuggest__results-item:active, + .autosuggest__results .autosuggest__results-item:focus, + .autosuggest__results .autosuggest__results-item.autosuggest__results-item--highlighted { + background-color: rgba(0, 0, 0, 0.04); + } + + .autosuggest__results { + overflow: scroll; + max-height: 400px; + } + + .autosuggest__results .autosuggest__results-after { + color: gray; + font-size: 11px; + margin-left: 0; + padding: 15px 13px 5px; + border-top: 1px solid lightgray; + } + + .highlightAutoItem { + background-color: rgba(0, 0, 0, 0.4); + } + \ No newline at end of file diff --git a/README.md b/README.md index 2b65146..61a4fcc 100644 --- a/README.md +++ b/README.md @@ -300,27 +300,28 @@ vue-autosuggest does not have an opinion about how you render the items in your ## [Props](#props) -| Prop | Type | Required | Description | -| :------------------------------------------ | :------- | :------: | :-------------------------------------------------------- | -| [`suggestions`](#suggestionsProp) | Array | ✓ | Suggestions to be rendered. e.g.`suggestions: [{data: ['harry','ron','hermione']}]` | -| [`input-props`](#inputPropsTable) | Object | ✓ | Add props to the ``. | -| [`section-configs`](#sectionConfigsProp) | Object | | Define multiple sections ``. | -| [`render-suggestion`](#renderSuggestion) | Function | | Tell vue-autosuggest how to render inside the `
  • ` tag. Overrides what is inside the default suggestion template slot. | -| [`get-suggestion-value`](#getSuggestionValue) | Function | | Tells vue-autosuggest what to put in the `` value | -| [`should-render-suggestions`](#shouldRenderSuggestions) | Function | | Tell vue-autosuggest if it should render the suggestions results popover | -| `component-attr-id-autosuggest` | String | | `id` of entire component | -| `component-attr-class-autosuggest-results-container` | String | | `class` of container of results container | -| `component-attr-class-autosuggest-results` | String | | `class` of results container | -| `component-attr-prefix` | String | | prefix to be used for results item classes/ids. default: `autosuggest` | +| Prop | Type | Required | Description | +| :------------------------------------------------------ | :------- | :------: | :----------------------------------------------------------------------------------------------------------------------- | +| [`suggestions`](#suggestionsProp) | Array | ✓ | Suggestions to be rendered. e.g.`suggestions: [{data: ['harry','ron','hermione']}]` | +| [`input-props`](#inputPropsTable) | Object | ✓ | Add props to the ``. | +| [`section-configs`](#sectionConfigsProp) | Object | | Define multiple sections ``. | +| [`render-suggestion`](#renderSuggestion) | Function | | Tell vue-autosuggest how to render inside the `
  • ` tag. Overrides what is inside the default suggestion template slot. | +| [`get-suggestion-value`](#getSuggestionValue) | Function | | Tells vue-autosuggest what to put in the `` value | +| [`should-render-suggestions`](#shouldRenderSuggestions) | Function | | Tell vue-autosuggest if it should render the suggestions results popover | +| `component-attr-id-autosuggest` | String | | `id` of entire component | +| `component-attr-class-autosuggest-results-container` | String | | `class` of container of results container | +| `component-attr-class-autosuggest-results` | String | | `class` of results container | +| `component-attr-class-autosuggest-item-highlight` | String | | `class` of highlighted item | +| `component-attr-prefix` | String | | prefix to be used for results item classes/ids. default: `autosuggest` | ### inputProps -| Prop | Type | Required | Description | -| :----------------------- | :------------------ | :--------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| [`id`](#inputPropsTable) | String | ✓ | id attribute on ``. | -| Any DOM Props | \* | | You can add any props to `` as the component will `v-bind` inputProps. Similar to rest spread in JSX. See more details here: https://vuejs.org/v2/api/#v-bind. The `name` attribute is set to "`q`" by default. | +| Prop | Type | Required | Description | +| :----------------------- | :----- | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [`id`](#inputPropsTable) | String | ✓ | id attribute on ``. | +| Any DOM Props | \* | | You can add any props to `` as the component will `v-bind` inputProps. Similar to rest spread in JSX. See more details here: https://vuejs.org/v2/api/#v-bind. The `name` attribute is set to "`q`" by default. | @@ -329,10 +330,10 @@ vue-autosuggest does not have an opinion about how you render the items in your Multiple sections can be defined in the `sectionConfigs` prop which defines the control behavior for each section. -| Prop | Type | Required | Description | -| :----------- | :------- | :------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `on-selected` | Function | ✓ | Determine behavior for what should happen when a suggestion is selected. e.g. Submit a form, open a link, update a vue model, tweet at Ken Wheeler etc. | -| `limit` | Number | | Limit each section by some value. Default: `Infinity` | +| Prop | Type | Required | Description | +| :------------ | :------- | :------: | :------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `on-selected` | Function | ✓ | Determine behavior for what should happen when a suggestion is selected. e.g. Submit a form, open a link, update a vue model, tweet at Ken Wheeler etc. | +| `limit` | Number | | Limit each section by some value. Default: `Infinity` | Below we have defined a `default` section and a `blog` section. The `blog` section has a component `type` of `url-section` which corresponds to which component the Autosuggest loads. When type is not @@ -445,7 +446,7 @@ For IE11 and below, some functionality may not work. For example, you will have Thanks goes to these people ([emoji key][emojis]): -| [
    Darren Jennings](https://darrenjennings.github.io)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Code") [📖](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Documentation") [🚇](#infra-darrenjennings "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Tests") [🎨](#design-darrenjennings "Design") [💡](#example-darrenjennings "Examples") | [
    Evgeniy Kulish](https://github.com/ekulish)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=ekulish "Code") [🎨](#design-ekulish "Design") [💡](#example-ekulish "Examples") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=ekulish "Tests") | [
    Scott Smith](https://github.com/scottadamsmith)
    [🐛](https://github.com/darrenjennings/vue-autosuggest/issues?q=author%3Ascottadamsmith "Bug reports") [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=scottadamsmith "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=scottadamsmith "Tests") | [
    Fernando Machuca](https://github.com/chuca)
    [🎨](#design-chuca "Design") | [
    BerniML](https://github.com/BerniML)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=BerniML "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=BerniML "Tests") | [
    Kristoffer Nordström](https://github.com/42tte)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=42tte "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=42tte "Tests") | +| [
    Darren Jennings](https://darrenjennings.github.io)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Code") [📖](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Documentation") [🚇](#infra-darrenjennings "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=darrenjennings "Tests") [🎨](#design-darrenjennings "Design") [💡](#example-darrenjennings "Examples") | [
    Evgeniy Kulish](https://github.com/ekulish)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=ekulish "Code") [🎨](#design-ekulish "Design") [💡](#example-ekulish "Examples") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=ekulish "Tests") | [
    Scott Smith](https://github.com/scottadamsmith)
    [🐛](https://github.com/darrenjennings/vue-autosuggest/issues?q=author%3Ascottadamsmith "Bug reports") [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=scottadamsmith "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=scottadamsmith "Tests") | [
    Fernando Machuca](https://github.com/chuca)
    [🎨](#design-chuca "Design") | [
    BerniML](https://github.com/BerniML)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=BerniML "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=BerniML "Tests") | [
    Kristoffer Nordström](https://github.com/42tte)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=42tte "Code") [⚠️](https://github.com/darrenjennings/vue-autosuggest/commits?author=42tte "Tests") | [
    Vivek Ashokan](https://github.com/vivekitis)
    [💻](https://github.com/darrenjennings/vue-autosuggest/commits?author=vivekitis "Code") [📖](https://github.com/darrenjennings/vue-autosuggest/commits?author=vivekitis "Documentation") [💡](#example-vivekitis "Examples") | | :---: | :---: | :---: | :---: | :---: | :---: | diff --git a/__tests__/__snapshots__/autosuggest.test.js.snap b/__tests__/__snapshots__/autosuggest.test.js.snap index c1a778a..ab973f2 100644 --- a/__tests__/__snapshots__/autosuggest.test.js.snap +++ b/__tests__/__snapshots__/autosuggest.test.js.snap @@ -18,65 +18,70 @@ exports[`Autosuggest can click outside document to trigger close 1`] = ` `; +exports[`Autosuggest can customize class for highlighted element 1`] = ` +
    +
    +
    +
    +
      +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
    • +
    +
      +
    • spike
    • +
    • bud
    • +
    • rover
    • +
    +
      +
    • sassy
    • +
    • tuesday
    • +
    • church
    • +
    +
      +
    • elephant
    • +
    • lion
    • +
    +
      +
    • something
    • +
    • something2
    • +
    +
    +
    +
    +`; + exports[`Autosuggest can customize css prefix 1`] = `
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
      -
    • - spike -
    • -
    • - bud -
    • -
    • - rover -
    • +
    • spike
    • +
    • bud
    • +
    • rover
      -
    • - sassy -
    • -
    • - tuesday -
    • -
    • - church -
    • +
    • sassy
    • +
    • tuesday
    • +
    • church
      -
    • - elephant -
    • -
    • - lion -
    • +
    • elephant
    • +
    • lion
      -
    • - something -
    • -
    • - something2 -
    • +
    • something
    • +
    • something2
    @@ -89,59 +94,29 @@ exports[`Autosuggest can customize ids and classes for container divs 1`] = `
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
      -
    • - spike -
    • -
    • - bud -
    • -
    • - rover -
    • +
    • spike
    • +
    • bud
    • +
    • rover
      -
    • - sassy -
    • -
    • - tuesday -
    • -
    • - church -
    • +
    • sassy
    • +
    • tuesday
    • +
    • church
      -
    • - elephant -
    • -
    • - lion -
    • +
    • elephant
    • +
    • lion
      -
    • - something -
    • -
    • - something2 -
    • +
    • something
    • +
    • something2
    @@ -155,21 +130,11 @@ exports[`Autosuggest can display section header 1`] = `
    • Suggestions
    • -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
    @@ -182,59 +147,29 @@ exports[`Autosuggest can display ul and li classNames 1`] = `
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
      -
    • - spike -
    • -
    • - bud -
    • -
    • - rover -
    • +
    • spike
    • +
    • bud
    • +
    • rover
      -
    • - sassy -
    • -
    • - tuesday -
    • -
    • - church -
    • +
    • sassy
    • +
    • tuesday
    • +
    • church
      -
    • - elephant -
    • -
    • - lion -
    • +
    • elephant
    • +
    • lion
      -
    • - something -
    • -
    • - something2 -
    • +
    • something
    • +
    • something2
    @@ -284,63 +219,33 @@ exports[`Autosuggest can render section slots 1`] = `
    @@ -353,66 +258,26 @@ exports[`Autosuggest can render simplest component with single onSelected 1`] =
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • -
    • - magic school bus -
    • -
    • - math mammoth light blue -
    • -
    • - handwriting -
    • -
    • - math -
    • -
    • - minecraft -
    • -
    • - free worksheets -
    • -
    • - 4th grade -
    • -
    • - snap circuits -
    • -
    • - bath toys -
    • -
    • - channies -
    • -
    • - fred -
    • -
    • - lego -
    • -
    • - math life of fred -
    • -
    • - multiplication -
    • -
    • - thinking tree -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
    • +
    • magic school bus
    • +
    • math mammoth light blue
    • +
    • handwriting
    • +
    • math
    • +
    • minecraft
    • +
    • free worksheets
    • +
    • 4th grade
    • +
    • snap circuits
    • +
    • bath toys
    • +
    • channies
    • +
    • fred
    • +
    • lego
    • +
    • math life of fred
    • +
    • multiplication
    • +
    • thinking tree
    @@ -454,21 +319,11 @@ exports[`Autosuggest can render suggestions 1`] = `
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
    @@ -499,59 +354,29 @@ exports[`Autosuggest highlights first option on keydown when previously closed 1
      -
    • - clifford kits -
    • -
    • - friendly chemistry -
    • -
    • - phonics -
    • -
    • - life of fred -
    • -
    • - life of fred math -
    • +
    • clifford kits
    • +
    • friendly chemistry
    • +
    • phonics
    • +
    • life of fred
    • +
    • life of fred math
      -
    • - spike -
    • -
    • - bud -
    • -
    • - rover -
    • +
    • spike
    • +
    • bud
    • +
    • rover
      -
    • - sassy -
    • -
    • - tuesday -
    • -
    • - church -
    • +
    • sassy
    • +
    • tuesday
    • +
    • church
      -
    • - elephant -
    • -
    • - lion -
    • +
    • elephant
    • +
    • lion
      -
    • - something -
    • -
    • - something2 -
    • +
    • something
    • +
    • something2
    @@ -565,21 +390,11 @@ exports[`Autosuggest is aria complete 1`] = `
    diff --git a/__tests__/autosuggest.test.js b/__tests__/autosuggest.test.js index 074c3a4..e44e717 100644 --- a/__tests__/autosuggest.test.js +++ b/__tests__/autosuggest.test.js @@ -930,4 +930,38 @@ describe("Autosuggest", () => { expect(wrapper.vm.currentIndex).toBe(-1) }); -}); + + it("can customize class for highlighted element", async () => { + const props = { ...defaultProps }; + props['componentAttrClassAutosuggestItemHighlight'] = 'custom-highlight-class' + props.inputProps = { ...defaultProps.inputProps }; + + const wrapper = mount(Autosuggest, { + propsData: props, + attachToDocument: true + }); + + const input = wrapper.find("input"); + expect(input.attributes("id", defaultProps.inputProps.id)).toBeTruthy(); + + input.trigger("click"); + input.setValue("G"); + input.trigger("keydown.down"); + input.trigger("keydown.enter"); + input.trigger("keydown.down"); + + expect(wrapper.findAll("li.custom-highlight-class")).toHaveLength(1) + + const item = wrapper.find("li.custom-highlight-class") + expect(item.attributes('data-suggestion-index')).toBe('0') + expect(input.attributes('aria-activedescendant')).toBe('autosuggest__results-item--0') + + const renderer = createRenderer(); + renderer.renderToString(wrapper.vm, (err, str) => { + if (err) { + return false; + } + expect(str).toMatchSnapshot(); + }); + }); +}); \ No newline at end of file diff --git a/src/Autosuggest.vue b/src/Autosuggest.vue index 3ba0a24..d591a2c 100644 --- a/src/Autosuggest.vue +++ b/src/Autosuggest.vue @@ -55,9 +55,7 @@ - {{ suggestion.item }} - + >{{ suggestion.item }} - @@ -86,7 +84,6 @@ diff --git a/src/parts/DefaultSection.js b/src/parts/DefaultSection.js index 97027eb..891a41e 100644 --- a/src/parts/DefaultSection.js +++ b/src/parts/DefaultSection.js @@ -28,23 +28,23 @@ const DefaultSection = { } }, methods: { - getItemIndex (i) { + getItemIndex(i) { return this.section.start_index + i; }, - getItemByIndex (i) { + getItemByIndex(i) { return this.section.data[i]; }, - onMouseEnter (event) { + onMouseEnter(event) { const idx = parseInt(event.currentTarget.getAttribute("data-suggestion-index")) this._currentIndex = idx this.$emit('updateCurrentIndex', idx) }, - onMouseLeave () { + onMouseLeave() { this.$emit('updateCurrentIndex', null) } }, // eslint-disable-next-line no-unused-vars - render (h) { + render(h) { const componentAttrPrefix = this.componentAttrPrefix const slots = { beforeSection: this.$scopedSlots[`before-section-${this.section.name}`], @@ -70,7 +70,7 @@ const DefaultSection = { const item = this.normalizeItemFunction(this.section.name, this.section.type, this.section.label, this.section.liClass, val) const itemIndex = this.getItemIndex(key) const isHighlighted = this._currentIndex === itemIndex || parseInt(this.currentIndex) === itemIndex - + const highlightClass = this.section.highlightClass; return h( "li", { @@ -83,7 +83,8 @@ const DefaultSection = { }, key: itemIndex, class: { - [`${componentAttrPrefix}__results-item--highlighted`]: isHighlighted, + [highlightClass]: isHighlighted, + //[`${componentAttrPrefix}__results-item--highlighted`]: isHighlighted, [`${componentAttrPrefix}__results-item`]: true, ...item.liClass }, diff --git a/src/stories/index.js b/src/stories/index.js index a6a8d8d..22ee7c5 100644 --- a/src/stories/index.js +++ b/src/stories/index.js @@ -167,7 +167,7 @@ storiesOf("Vue-Autosuggest", module) onClick: this.onClick, placeholder: "Type 'g'" }, - onSelected(i){ + onSelected(i) { action('Selected')(i); } }; @@ -518,8 +518,8 @@ storiesOf("Vue-Autosuggest", module) } })) .add("with section before/after slots", () => ({ - components: { Autosuggest }, - template: `
    + components: { Autosuggest }, + template: `
    You have selected {{selected}}
    `, - data() { - return { - selected: "", - limit: 10, - query: '', - options: [ - { - data: sharedData.options - } - ], - inputProps: { - id: "autosuggest__input", - placeholder: "Type 'g'" + data() { + return { + selected: "", + limit: 10, + query: '', + options: [ + { + data: sharedData.options + } + ], + inputProps: { + id: "autosuggest__input", + placeholder: "Type 'g'" + } + }; + }, + computed: { + filteredOptions() { + const suggestionsData = this.options[0].data.filter(item => { + return item.toLowerCase().indexOf(this.query.toLowerCase()) > -1; + }); + + return [ + { + label: "Section 1", + data: suggestionsData, + limit: 2 + }, + { + label: "Section 2", + data: suggestionsData.map(a => `${a} ${this.rando()}`) + .concat(suggestionsData.map(a => `${a} ${this.rando()}`)) + .concat(suggestionsData.map(a => `${a} ${this.rando()}`)) } - }; + ] + } + }, + methods: { + rando() { + return Math.floor(Math.random() * (100 - 1)) + 1 }, - computed: { - filteredOptions() { - const suggestionsData = this.options[0].data.filter(item => { - return item.toLowerCase().indexOf(this.query.toLowerCase()) > -1; - }); + onSelected(item) { + action('Selected')(item.item) - return [ - { - label: "Section 1", - data: suggestionsData, - limit: 2 - }, - { - label: "Section 2", - data: suggestionsData.map(a => `${a} ${this.rando()}` ) - .concat(suggestionsData.map(a => `${a} ${this.rando()}`)) - .concat(suggestionsData.map(a => `${a} ${this.rando()}`)) - } - ] - } + this.query = item.item }, - methods: { - rando(){ - return Math.floor(Math.random() * (100 - 1)) + 1 + onInputChange(text) { + action('onInputChange')(text) + if (text === null) { + return; + } + this.query = text + } + } + })) + .add("custom highlight class", () => ({ + components: { Autosuggest }, + template: `
    +
    You have selected '{{selected}}'
    +
    + +
    +
    `, + data() { + return { + selected: "", + filteredOptions: [], + options: [{ data: sharedData.options.slice(0, 10) }], + inputProps: { + id: "autosuggest__input", + placeholder: "Type 'e'" }, - onSelected(item) { - action('Selected')(item.item) - - this.query = item.item + componentAttrClassAutosuggestItemHighlight: 'highlightAutoItem', + onSelected: item => { + action("Selected")(item) + this.selected = item; + } + }; + }, + methods: sharedData.methods + })) + .add("multiple instances with custom highlight class", () => ({ + components: { Autosuggest }, + template: ` +
    +
    +

    Tab throw each component and use arrow keys to test isolation of functionality.

    +
    +
    + + + + + + +
    +
    + `, + data() { + return { + selected: [], + limit: 10, + filteredOptions: { + 0: [], + 1: [], + 2: [] }, - onInputChange(text) { - action('onInputChange')(text) - if (text === null) { - return; + options: [ + { + data: [...sharedData.options] } - this.query = text + ], + inputProps: { + id: "autosuggest__input", + onClick: this.onClick, + placeholder: "Type 'g'" + }, + componentAttrClassAutosuggestItemHighlight: 'highlightAutoItem', + }; + }, + methods: { + onInputChange(text, index) { + action('onInputChange')(text) + if (text === null) { + return; } + const filteredData = this.options[0].data.filter(item => { + return item.toLowerCase().indexOf(text.toLowerCase()) > -1; + }); + + this.filteredOptions[index] = [{ data: filteredData }]; } - })); + } + })) + ;