From 731fd2082fa0ad1b0396748ad1e0e587446c4320 Mon Sep 17 00:00:00 2001 From: practicatto Date: Fri, 22 Mar 2024 18:15:47 -0500 Subject: [PATCH] add clear to Ktextbox add tests and fix clear button remove unnecessary styles and add kiconbutton instead of button fix tests with component fix linter fix borders add requested changes add aria label add link in changelog pr591 add docs --- CHANGELOG.md | 11 ++ docs/pages/playground.vue | 3 - lib/KTextbox/__tests__/KTextbox.spec.js | 56 +++++++ lib/KTextbox/index.vue | 13 ++ lib/keen/UiTextbox.vue | 186 +++++++++++++++--------- 5 files changed, 196 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7e51473..5ca43a5ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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:** - + +[#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:** - diff --git a/docs/pages/playground.vue b/docs/pages/playground.vue index bf32354b2..686423285 100644 --- a/docs/pages/playground.vue +++ b/docs/pages/playground.vue @@ -24,9 +24,6 @@ - - - diff --git a/lib/KTextbox/__tests__/KTextbox.spec.js b/lib/KTextbox/__tests__/KTextbox.spec.js index 010bbd49e..20d0d8eb6 100644 --- a/lib/KTextbox/__tests__/KTextbox.spec.js +++ b/lib/KTextbox/__tests__/KTextbox.spec.js @@ -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(''); + }); + }); }); diff --git a/lib/KTextbox/index.vue b/lib/KTextbox/index.vue index 1dea289cd..8b6a16dcb 100644 --- a/lib/KTextbox/index.vue +++ b/lib/KTextbox/index.vue @@ -7,6 +7,8 @@ class="textbox" :label="label" :disabled="disabled" + :clearAriaLabel="clearAriaLabel" + :clearable="clearable" :invalid="showInvalidMessage" :error="invalidText" :autofocus="autofocus" @@ -50,6 +52,10 @@ type: String, required: true, }, + /** + * Value of the clear aria label + */ + clearAriaLabel: String, /** * Value of the text field */ @@ -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. diff --git a/lib/keen/UiTextbox.vue b/lib/keen/UiTextbox.vue index a22c06629..ea8579b74 100644 --- a/lib/keen/UiTextbox.vue +++ b/lib/keen/UiTextbox.vue @@ -9,6 +9,7 @@ functionality. -->
+
@@ -17,68 +18,69 @@