From 13a6677d3f7d0699d4ed1060e4adc63ad4a0afb7 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 --- CHANGELOG.md | 9 ++ docs/pages/playground.vue | 3 - lib/KTextbox/__tests__/KTextbox.spec.js | 56 ++++++++ lib/KTextbox/index.vue | 8 ++ lib/keen/UiTextbox.vue | 184 +++++++++++++++--------- 5 files changed, 187 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7e51473..f4860f6ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ 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:** - + - [#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..ae94adb39 100644 --- a/lib/KTextbox/index.vue +++ b/lib/KTextbox/index.vue @@ -7,6 +7,7 @@ class="textbox" :label="label" :disabled="disabled" + :clearable="clearable" :invalid="showInvalidMessage" :error="invalidText" :autofocus="autofocus" @@ -142,6 +143,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..4b6074060 100644 --- a/lib/keen/UiTextbox.vue +++ b/lib/keen/UiTextbox.vue @@ -9,6 +9,7 @@ functionality. -->
+
@@ -17,68 +18,68 @@