Skip to content

Commit

Permalink
feat(text-area): binds component attributes to native textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebritor committed Apr 15, 2023
1 parent a6567ed commit c504cdb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/CvTextArea/CvTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
</label>
<div :class="`${carbonPrefix}--text-area__wrapper`">
<textarea
:id="cvId"
:class="[`${carbonPrefix}--text-area`]"
v-bind="$attrs"
:value="modelValue"
:id="cvId"
@input="$event => $emit('update:modelValue', $event.target.value)"
></textarea>
</div>
Expand All @@ -26,3 +27,9 @@ const props = defineProps({
const cvId = useCvId(props);
</script>

<script>
export default {
inheritAttrs: false,
};
</script>
23 changes: 23 additions & 0 deletions src/components/CvTextArea/__tests__/CvTextArea.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,27 @@ describe('CvTextArea', () => {
const textarea = getByLabelText(dummyLabel);
expect(textarea).toBeDefined();
});

describe('Attribute & event binding', () => {
it('binds attributes to native textarea', async () => {
const dummyName = 'dummy-name';
const { container } = render(CvTextArea, {
attrs: { name: dummyName },
});

const textarea = container.querySelector('textarea');
expect(textarea.getAttribute('name')).toBe(dummyName);
expect(container.firstChild.getAttribute('name')).not.toBe(dummyName);
});

it('does not overwrite native textarea value if attribute value is set', async () => {
const dummyValue = 'Dummy Value';
const { container } = render(CvTextArea, {
attrs: { value: dummyValue },
});

const textarea = container.querySelector('textarea');
expect(textarea.value).toBe('');
});
});
});

0 comments on commit c504cdb

Please sign in to comment.