Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTextbox: Support a "clearable" prop to show a clear button #591

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ Changelog is rather internal in nature. See release notes for the public overvie

## Version 4.x.x (`release-v4` branch)

- [#591]
- **Description:** Added a clearable prop to KTextbox
- **Products impact:** -
- **Addresses:** https://github.com/learningequality/kolibri-design-system/issues/584
- **Components:** `KTextbox`
- **Breaking:** no
- **Impacts a11y:** no
- **Guidance:** -

practicatto marked this conversation as resolved.
Show resolved Hide resolved
[#591]: https://github.com/learningequality/kolibri-design-system/pull/591

- [#582]
- **Description:** Upgrade popper.js from 1.14.6 to 1.16.1
- **Products impact:** -
Expand Down
3 changes: 0 additions & 3 deletions docs/pages/playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

<!-- Play around with your component here: -->




</div>

</template>
Expand Down
56 changes: 56 additions & 0 deletions lib/KTextbox/__tests__/KTextbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,60 @@ describe('KTextbox component', () => {
expect(wrapper.emitted().input).toBeTruthy();
});
});
describe('KTextbox with clearable', () => {
it('should have the clear button when clearable is true and there is text in the input', async () => {
const wrapper = mount(KTextbox, {
propsData: {
clearable: true,
},
});
const input = wrapper.find('input');
input.element.value = 'test';
input.trigger('input');
await wrapper.vm.$nextTick();
const clearButton = wrapper.find('[data-test="clearIcon"]');
expect(clearButton.exists()).toBeTruthy();
});
it('should not show the clear button when clearable is true and there is no text in the input', async () => {
const wrapper = mount(KTextbox, {
propsData: {
clearable: true,
},
});

const input = wrapper.find('input');
input.element.value = '';
input.trigger('input');
await wrapper.vm.$nextTick();
expect(wrapper.find('[data-test="clearIcon"]').exists()).toBeFalsy();
});

it('should not show the clear button when clearable is false and there is text in the input', async () => {
const wrapper = mount(KTextbox, {
propsData: {
clearable: false,
},
});
const input = wrapper.find('input');
input.element.value = 'test';
input.trigger('input');
await wrapper.vm.$nextTick();
expect(wrapper.find('[data-test="clearIcon"]').exists()).toBeFalsy();
});
it('should clear the input when clear button is clicked', async () => {
const wrapper = mount(KTextbox, {
propsData: {
clearable: true,
},
});
const input = wrapper.find('input');
input.element.value = 'test';
input.trigger('input');
await wrapper.vm.$nextTick();
const clearButton = wrapper.find('[data-test="clearIcon"]');
clearButton.trigger('click');
await wrapper.vm.$nextTick();
expect(wrapper.find('input').element.value).toBe('');
});
});
});
13 changes: 13 additions & 0 deletions lib/KTextbox/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class="textbox"
:label="label"
:disabled="disabled"
:clearAriaLabel="clearAriaLabel"
:clearable="clearable"
:invalid="showInvalidMessage"
:error="invalidText"
:autofocus="autofocus"
Expand Down Expand Up @@ -50,6 +52,10 @@
type: String,
required: true,
},
/**
* Value of the aria-label for clear button
*/
clearAriaLabel: { type: String, default: 'Clear' },
/**
* Value of the text field
*/
Expand Down Expand Up @@ -142,6 +148,13 @@
type: Boolean,
default: false,
},
/**
* When set to `true`, the component displays a clear button inside the input field.
*/
clearable: {
type: Boolean,
default: false,
},
/**
* @ignore
* Whether or not to display as a floating label.
Expand Down
Loading