Skip to content

Commit

Permalink
fix(TextArea): adjust styling for clear icon
Browse files Browse the repository at this point in the history
  • Loading branch information
lukicenturi committed Sep 26, 2024
1 parent fac26ea commit ff72c2e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
28 changes: 28 additions & 0 deletions src/components/forms/text-area/RuiTextArea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,32 @@ describe('forms/TextArea', () => {

expect((wrapper.find('textarea:not([aria-hidden="true"])').element as HTMLTextAreaElement).value).toBe(text);
});

it('clearable', async () => {
const text = 'test text';
const wrapper = createWrapper({
props: {
clearable: true,
modelValue: text,
},
});

expect(wrapper.find('.clear-btn').exists()).toBeTruthy();

expect(wrapper.find('textarea').element.value).toBe(text);
await wrapper.find('.clear-btn').trigger('click');
expect(wrapper.find('textarea').element.value).toBe('');
await nextTick();

// Clear button not rendered if value is empty
expect(wrapper.find('.clear-btn').exists()).toBeFalsy();

// Clear button not rendered if the textarea is disabled
await wrapper.setProps({ disabled: true });
expect(wrapper.find('.clear-btn').exists()).toBeFalsy();

// Clear button not rendered if the textarea is readonly
await wrapper.setProps({ disabled: false, readonly: true });
expect(wrapper.find('.clear-btn').exists()).toBeFalsy();
});
});
17 changes: 5 additions & 12 deletions src/components/forms/text-area/RuiTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const prepend = ref<HTMLDivElement>();
const append = ref<HTMLDivElement>();
const textarea = ref<HTMLTextAreaElement>();
const textareaSizer = ref<HTMLTextAreaElement>();
const focusedDebounced = ref(false);
const css = useCssModule();
const attrs = useAttrs();
Expand Down Expand Up @@ -165,14 +164,7 @@ function computeFieldHeight(newVal?: string, oldVal?: string) {
}
const { focused } = useFocus(textarea);
watchDebounced(
focused,
(focused) => {
set(focusedDebounced, focused);
},
{ debounce: 500 },
);
const focusedDebounced = refDebounced(focused, 500);
watch(modelValue, computeFieldHeight);
onMounted(computeFieldHeight);
Expand Down Expand Up @@ -255,9 +247,10 @@ onMounted(computeFieldHeight);
variant="text"
type="button"
icon
class="!p-2"
:color="color"
@click="clearIconClicked()"
class="!p-2 clear-btn"
color="error"
tabindex="-1"
@click.stop="clearIconClicked()"
>
<RuiIcon
name="close-line"
Expand Down

0 comments on commit ff72c2e

Please sign in to comment.