Skip to content

Commit

Permalink
add clear to Ktextbox
Browse files Browse the repository at this point in the history
add tests and fix clear button
  • Loading branch information
practicatto committed Mar 25, 2024
1 parent 9dcacd9 commit 6835d6d
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 467 deletions.
12 changes: 4 additions & 8 deletions docs/pages/playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
/> -->

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




</div>

</template>
Expand All @@ -35,10 +31,10 @@
<script>
/*
Playground is a Vue component too,
so you can also use `data`, `methods`, etc.
as usual if helpful
*/
Playground is a Vue component too,
so you can also use `data`, `methods`, etc.
as usual if helpful
*/
export default {
name: 'Playground',
data() {
Expand Down
32 changes: 32 additions & 0 deletions lib/KTextbox/__tests__/KTextbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,35 @@ describe('KTextbox component', () => {
});
});
});

describe('KTextbox with clearable', () => {
it('should have clearable 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('.ui-clear-button');
expect(clearButton.exists()).toBeTruthy();
});

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('.ui-clear-button');
clearButton.trigger('click');
await wrapper.vm.$nextTick();
expect(wrapper.find('input').element.value).toBe('');
});
});
8 changes: 8 additions & 0 deletions lib/KTextbox/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class="textbox"
:label="label"
:disabled="disabled"
:clearable="clearable"
:invalid="showInvalidMessage"
:error="invalidText"
:autofocus="autofocus"
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 6835d6d

Please sign in to comment.