Skip to content

Commit

Permalink
fix(comp: checkbox-group): invalid disabled in dataSource (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzaijiang committed Mar 31, 2022
1 parent 74fb409 commit 0f43a09
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/components/checkbox/__tests__/checkboxGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ describe('CheckboxGroup', () => {
test('dataSource work', async () => {
let dataSource = [
{ label: 'option1', value: 'option1' },
{ label: 'option2', value: 'option2' },
{ label: 'option2', value: 'option2', disabled: true },
]
const wrapper = CheckboxGroupMount({ props: { dataSource } })

expect(wrapper.findAll('.ix-checkbox').length).toBe(2)

expect(wrapper.findAll('.ix-checkbox-disabled').length).toBe(1)

dataSource = [
{ label: 'option1', value: 'option1' },
{ label: 'option2', value: 'option2' },
Expand Down
2 changes: 1 addition & 1 deletion packages/components/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const useCheckbox = (props: CheckboxProps, checkboxGroup: CheckboxGroupContext |
if (checkboxGroup) {
const { props: groupProps, accessor } = checkboxGroup
isChecked = computed(() => (accessor.valueRef.value ?? []).includes(props.value ?? props.trueValue))
isDisabled = computed(() => accessor.disabled.value ?? !!props.disabled)
isDisabled = computed(() => accessor.disabled.value || !!props.disabled)

handleBlur = (evt: FocusEvent) => {
isFocused.value = false
Expand Down
4 changes: 3 additions & 1 deletion packages/components/radio/__tests__/radioGroup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ describe('RadioGroup', () => {

test('dataSource work', async () => {
let dataSource = [
{ label: 'Beijing', value: 'a' },
{ label: 'Beijing', value: 'a', disabled: true },
{ label: 'Shanghai', value: 'b' },
]
const wrapper = RadioGroupMount({ props: { dataSource } })

expect(wrapper.findAll('.ix-radio-disabled').length).toBe(1)

expect(wrapper.findAll('.ix-radio').length).toBe(2)

dataSource = [
Expand Down
2 changes: 1 addition & 1 deletion packages/components/radio/src/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const useRadio = (
if (radioGroup) {
const { accessor, props: groupProps } = radioGroup
isChecked = computed(() => accessor.valueRef.value === props.value)
isDisabled = computed(() => props.disabled ?? accessor.disabled.value)
isDisabled = computed(() => accessor.disabled.value || !!props.disabled)
handleBlur = (evt: FocusEvent) => {
isFocused.value = false
callEmit(props.onBlur, evt)
Expand Down

0 comments on commit 0f43a09

Please sign in to comment.