Skip to content

Commit

Permalink
fix(inputProps) make reactive (#143)
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
darrenjennings authored Sep 11, 2019
1 parent 0f9265e commit 48fb754
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions __tests__/autosuggest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,4 +679,28 @@ describe("Autosuggest", () => {
expect(str).toMatchSnapshot();
});
});

it("can modify input props", async () => {
const Parent = {
template: `<div>
<Autosuggest
:suggestions="[{data:['Frodo']}]"
:input-props="{id:'autosuggest', placeholder: ph}" />
</div>
`,
components: { Autosuggest },
data: () => {
return {
'ph': 'Type here...'
}
}
}

const wrapper = mount(Parent);
const input = wrapper.find('input[type="text"]')
expect(input.attributes("placeholder")).toBe('Type here...');

wrapper.setData({ ph: 'Please type here...' })
expect(input.attributes("placeholder")).toBe('Please type here...')
});
});
8 changes: 6 additions & 2 deletions src/Autosuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export default {
currentItem: null,
loading: false /** Helps with making sure the dropdown doesn't stay open after certain actions */,
didSelectFromOptions: false,
internal_inputProps: {}, // Nest default prop values don't work currently in Vue
defaultInputProps: {
type: 'text',
autocomplete: "off",
Expand All @@ -195,6 +194,12 @@ export default {
};
},
computed: {
internal_inputProps() {
return {
...this.defaultInputProps,
...this.inputProps
}
},
listeners() {
return {
...this.$listeners,
Expand Down Expand Up @@ -292,7 +297,6 @@ export default {
}
},
created() {
this.internal_inputProps = { ...this.defaultInputProps, ...this.inputProps };
this.loading = true;
},
mounted() {
Expand Down

0 comments on commit 48fb754

Please sign in to comment.