Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RadioGroup): disabled state not passing on RadioGroupItem #870

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
2 changes: 1 addition & 1 deletion packages/radix-vue/src/RadioGroup/Radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function handleClick(event: MouseEvent) {
:aria-checked="checked"
:aria-label="ariaLabel"
:as-child="asChild"
:disabled="disabled ? true : undefined"
:disabled="disabled ? '' : undefined"
:data-state="checked ? 'checked' : 'unchecked'"
:data-disabled="disabled ? '' : undefined"
:value="value"
Expand Down
29 changes: 29 additions & 0 deletions packages/radix-vue/src/RadioGroup/RadioGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,35 @@ describe('given a default RadioGroup', () => {
})
})

describe('given disabled RadioGroup', () => {
let wrapper: VueWrapper<InstanceType<typeof RadioGroup>>
let radios: DOMWrapper<HTMLElement>[]

beforeEach(() => {
document.body.innerHTML = ''
wrapper = mount(RadioGroup, { attachTo: document.body, props: { disabled: true } })
radios = wrapper.findAll('[role=radio]')
})

it('should pass axe accessibility tests', async () => {
expect(await axe(wrapper.element)).toHaveNoViolations()
})

it('should have default selected', () => {
expect(radios[0].attributes('data-state')).toBe('checked')
})

it.each([[0, 'checked'], [1, 'unchecked'], [2, 'unchecked']])('should not select any item', async (input, output) => {
await radios[input].trigger('click')
expect(radios[input].attributes('data-state')).toBe(output)
})

it.each([[0], [1], [2]])('should have disabled attribute on item', async (input) => {
expect(radios[input].attributes('disabled')).toBe('')
expect(radios[input].attributes('data-disabled')).toBe('true')
})
})

describe('given radio in a form', async () => {
const wrapper = mount({
props: ['handleSubmit'],
Expand Down
1 change: 1 addition & 0 deletions packages/radix-vue/src/RadioGroup/RadioGroupItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function handleFocus() {
:ref="forwardRef"
:checked="checked"
:required="required"
:disabled="disabled"
@update:checked="rootContext.changeModelValue(value)"
@keydown.enter.prevent
@focus="handleFocus"
Expand Down
4 changes: 4 additions & 0 deletions packages/radix-vue/src/RadioGroup/story/_RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import { ref } from 'vue'
import { RadioGroupIndicator, RadioGroupItem, RadioGroupRoot } from '../'

defineProps<{
disabled?: boolean
}>()
const radioStateSingle = ref('default')
</script>

<template>
<RadioGroupRoot
v-model="radioStateSingle"
:loop="false"
:disabled="disabled"
class="flex flex-col gap-2.5"
aria-label="View density"
orientation="vertical"
Expand Down
Loading