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(components): [radio-button] model-value click style lost and format test file #16692

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/components/radio/__tests__/radio.test.tsx
Expand Up @@ -141,6 +141,7 @@ describe('Radio group', () => {
expect(radio.value).toEqual(3)
expect(radio1.classes()).toContain('is-checked')
})

it('change event', async () => {
const radio = ref(3)
const data = ref<RadioProps['modelValue']>(0)
Expand All @@ -161,6 +162,7 @@ describe('Radio group', () => {
await nextTick()
expect(data.value).toEqual(6)
})

it('change event only triggers on user input', async () => {
const radio = ref(3)
const data = ref<RadioProps['modelValue']>(0)
Expand All @@ -181,6 +183,7 @@ describe('Radio group', () => {
await nextTick()
expect(data.value).toEqual(0)
})

it('disabled when children is radio button', async () => {
const radio = ref(3)
const wrapper = mount(() => (
Expand Down Expand Up @@ -224,6 +227,7 @@ describe('Radio Button', () => {
expect(radio2.classes()).toContain('is-active')
expect(radio.value).toEqual(6)
})

it('custom color', () => {
const radio = ref(3)
const wrapper = mount(() => (
Expand All @@ -242,6 +246,7 @@ describe('Radio Button', () => {
'background-color: rgb(0, 0, 0); border-color: #000; box-shadow: -1px 0 0 0 #000; color: rgb(255, 255, 0);'
)
})

it('change event', async () => {
const radio = ref(3)
const data = ref<RadioProps['modelValue']>(0)
Expand All @@ -263,6 +268,7 @@ describe('Radio Button', () => {
await radio2?.trigger('click')
expect(radio.value).toEqual(6)
})

it('change event only triggers on user input', async () => {
const radio = ref(3)
const data = ref<RadioProps['modelValue']>(0)
Expand Down
48 changes: 26 additions & 22 deletions packages/theme-chalk/src/radio-button.scss
Expand Up @@ -73,33 +73,37 @@
}
}

@include e(original-radio) {
opacity: 0;
outline: none;
position: absolute;
z-index: -1;

&:checked {
& + .#{$namespace}-radio-button__inner {
color: getCssVarWithDefault(
('radio-button', 'checked-text-color'),
map.get($radio-button, 'checked-text-color')
);
background-color: getCssVarWithDefault(
'radio-button-checked-bg-color',
map.get($radio-button, 'checked-bg-color')
);
border-color: getCssVarWithDefault(
'radio-button-checked-border-color',
map.get($radio-button, 'checked-border-color')
);
box-shadow: -1px 0 0 0
getCssVarWithDefault(
@include when(active) {
@include e(original-radio) {
&:not(:disabled) {
& + .#{$namespace}-radio-button__inner {
color: getCssVarWithDefault(
('radio-button', 'checked-text-color'),
map.get($radio-button, 'checked-text-color')
);
background-color: getCssVarWithDefault(
'radio-button-checked-bg-color',
map.get($radio-button, 'checked-bg-color')
);
border-color: getCssVarWithDefault(
'radio-button-checked-border-color',
map.get($radio-button, 'checked-border-color')
);
box-shadow: -1px 0 0 0
getCssVarWithDefault(
'radio-button-checked-border-color',
map.get($radio-button, 'checked-border-color')
);
}
}
}
}

@include e(original-radio) {
opacity: 0;
outline: none;
position: absolute;
z-index: -1;

&:focus-visible {
& + .#{$namespace}-radio-button__inner {
Expand Down