Skip to content

Commit

Permalink
feat(text-input): setup id & label association
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebritor committed Apr 11, 2023
1 parent 60e7b5a commit 94f0972
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/CvTextInput/CvTextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
`${carbonPrefix}--text-input-wrapper`,
]"
>
<label :class="[`${carbonPrefix}--label`]">
<label :for="cvId" :class="[`${carbonPrefix}--label`]">
{{ label }}
</label>
<div :class="[`${carbonPrefix}--text-input__field-wrapper`]">
<input
:class="[`${carbonPrefix}--text-input`]"
type="text"
:id="cvId"
:value="modelValue"
@input="$event => $emit('update:modelValue', $event.target.value)"
/>
Expand All @@ -22,11 +23,14 @@

<script setup>
import { carbonPrefix } from '../../global/settings';
import { useCvId, props as propsCvId } from '../../use/cvId';
const props = defineProps({
label: String,
modelValue: String,
...propsCvId,
});
const cvId = useCvId(props);
const emit = defineEmits(['update:modelValue']);
</script>
10 changes: 10 additions & 0 deletions src/components/CvTextInput/__tests__/CvTextInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ describe('CvTextInput', () => {
const input = container.querySelector('input');
expect(input.value).toBe(dummyInitialText);
});

it('associates label & native input', async () => {
const dummyLabel = 'Dummy Label';
const { getByLabelText } = render(CvTextInput, {
props: { label: dummyLabel },
});

const input = getByLabelText(dummyLabel);
expect(input).toBeDefined();
});
});

0 comments on commit 94f0972

Please sign in to comment.