Skip to content

Commit a97bf69

Browse files
refactor(radio): radio (#1676)
Co-authored-by: huaweidevcloud <[email protected]>
1 parent eec77d2 commit a97bf69

File tree

10 files changed

+22
-10
lines changed

10 files changed

+22
-10
lines changed

packages/devui-vue/devui/radio/__tests__/radio-button.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mount } from '@vue/test-utils';
22
import { ref } from 'vue';
33
import DRadioButton from '../src/radio-button';
4-
import { useNamespace } from '../../shared/hooks/use-namespace';
4+
import { useNamespace } from '@devui/shared/utils';
55

66
const nsClass = useNamespace('radio-button', true);
77
const baseClass = nsClass.b();

packages/devui-vue/devui/radio/__tests__/radio-group.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ref } from 'vue';
33
import DRadioGroup from '../src/radio-group';
44
import DRadio from '../src/radio';
55
import DRadioButton from '../src/radio-button';
6-
import { useNamespace } from '../../shared/hooks/use-namespace';
6+
import { useNamespace } from '@devui/shared/utils';
77

88
const ns = useNamespace('radio-group', false);
99
const baseClass = ns.b();

packages/devui-vue/devui/radio/__tests__/radio.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mount } from '@vue/test-utils';
22
import { ref } from 'vue';
33
import DRadio from '../src/radio';
4-
import { useNamespace } from '../../shared/hooks/use-namespace';
4+
import { useNamespace } from '@devui/shared/utils';
55

66
const nsClass = useNamespace('radio', true);
77
const baseClass = nsClass.b();

packages/devui-vue/devui/radio/src/radio-button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineComponent, SetupContext } from 'vue';
22
import { radioProps, RadioProps } from './radio-types';
3-
import { useNamespace } from '../../shared/hooks/use-namespace';
3+
import { useNamespace } from '@devui/shared/utils';
44
import { useRadio, useRadioButton } from './use-radio';
55
import './radio-button.scss';
66

packages/devui-vue/devui/radio/src/radio-group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineComponent, SetupContext } from 'vue';
22
import DRadio from './radio';
33
import { radioGroupProps, RadioGroupProps } from './radio-types';
4-
import { useNamespace } from '../../shared/hooks/use-namespace';
4+
import { useNamespace } from '@devui/shared/utils';
55
import { useRadioGroup } from './use-radio';
66
import './radio-group.scss';
77

packages/devui-vue/devui/radio/src/radio-types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { InjectionKey, PropType, Ref, ExtractPropTypes, ComputedRef } from 'vue';
2-
export type valueTypes = string | number | boolean;
2+
export type valueTypes = string | number | boolean | undefined;
33
export type sizeTypes = 'lg' | 'md' | 'sm';
44

55
/** radio、radio-group 共用 props */
@@ -42,6 +42,10 @@ export const radioProps = {
4242
type: Boolean,
4343
default: false,
4444
},
45+
canCancelSelect: {
46+
type: Boolean,
47+
default: false,
48+
},
4549
} as const;
4650

4751
/** radio-group 的 props */

packages/devui-vue/devui/radio/src/radio.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $radio-label-height-map: (
4343
}
4444

4545
.#{$devui-prefix}-radio__material-inner {
46-
fill: $devui-icon-fill-active-hover;
46+
fill: $devui-brand;
4747
}
4848
}
4949

packages/devui-vue/devui/radio/src/radio.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineComponent, SetupContext } from 'vue';
22
import { radioProps, RadioProps } from './radio-types';
3-
import { useNamespace } from '../../shared/hooks/use-namespace';
3+
import { useNamespace } from '@devui/shared/utils';
44
import { useRadio } from './use-radio';
55
import './radio.scss';
66

@@ -31,7 +31,7 @@ export default defineComponent({
3131
name={radioName.value}
3232
class={ns.e('input')}
3333
disabled={isDisabled.value}
34-
onChange={handleChange}
34+
onClick={handleChange}
3535
value={props.value}
3636
checked={isChecked.value}
3737
/>

packages/devui-vue/devui/radio/src/use-radio.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ export function useRadio(props: RadioProps, ctx: SetupContext): UseRadioFn {
4242
};
4343

4444
const handleChange = async (event: Event) => {
45-
const _value = props.value;
45+
let _value;
46+
if (props.canCancelSelect && isChecked.value) {
47+
_value = undefined;
48+
} else if (isChecked.value) {
49+
return;
50+
} else {
51+
_value = props.value;
52+
}
4653
const canChange = await judgeCanChange(_value);
4754

4855
// 不可以切换

packages/devui-vue/docs/components/radio/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ export default defineComponent({
391391
| before-change | `Function / Promise` | -- | 可选,radio 切换前的回调函数,<br>返回 false 可以阻止 radio 切换 | [回调切换](#radio-根据条件终止切换操作) |
392392
| border | `boolean` | false | 可选, 是否有边框 | [边框](#尺寸和边框) |
393393
| size | [IRadioSize](#iradiosize) | md | 可选, radio 尺寸,只有在 border 属性存在时生效 | [尺寸](#尺寸和边框) |
394+
| can-cancel-select | `boolean` | false | 可选, 选中后,再次点击是否可取消选中 | |
394395

395396
### Radio 事件
396397

0 commit comments

Comments
 (0)