Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/components/NcCheckboxRadioSwitch/NcCheckboxContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
-->

<template>
<span :id="!isButtonType ? `${id}-label` : undefined"
class="checkbox-content"
<span class="checkbox-content"
:class="{
['checkbox-content-' + type]: true,
'checkbox-content--button-variant': buttonVariant,
Expand Down Expand Up @@ -84,14 +83,6 @@ export default {
},

props: {
/**
* Unique id attribute of the input to label
*/
id: {
type: String,
default: null,
},

/**
* Class for the icon element
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export default {
:name="name"
v-bind="$attrs"
v-on="listeners">
<NcCheckboxContent :id="id"
<NcCheckboxContent :id="!isButtonType ? `${id}-label` : undefined"
class="checkbox-radio-switch__content"
icon-class="checkbox-radio-switch__icon"
text-class="checkbox-radio-switch__text"
Expand Down
31 changes: 30 additions & 1 deletion tests/unit/components/NcCheckboxRadioSwitch/checkbox.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/

import { shallowMount } from '@vue/test-utils'
import { mount, shallowMount } from '@vue/test-utils'
import NcCheckboxRadioSwitch from '../../../../src/components/NcCheckboxRadioSwitch/NcCheckboxRadioSwitch.vue'

describe('NcCheckboxRadioSwitch', () => {
Expand Down Expand Up @@ -49,4 +49,33 @@ describe('NcCheckboxRadioSwitch', () => {
expect(input.attributes('aria-invalid')).toBe('true')
expect(input.attributes('aria-errormessage')).toBe('id-test')
})

it('sets aria-labelledby attribute correctly', () => {
const wrapper = mount(NcCheckboxRadioSwitch, {
propsData: {
id: 'test-id',
},
slots: {
default: 'Test',
},
})

expect(wrapper.find('input').attributes('aria-labelledby')).toBe('test-id-label')
expect(wrapper.findComponent({ name: 'NcCheckboxContent' }).attributes('id')).toBe('test-id-label')
})

it('does not set id on button content', () => {
const wrapper = mount(NcCheckboxRadioSwitch, {
propsData: {
id: 'test-id',
type: 'button',
},
slots: {
default: 'Test',
},
})

expect(wrapper.find('input').exists()).toBe(false)
expect(wrapper.findComponent({ name: 'NcCheckboxContent' }).attributes('id')).toBe(undefined)
})
})