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

feat(radio): radioGroup组件change事件添加name属性 #4491

Merged
merged 1 commit into from
Aug 20, 2024
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 src/radio/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const RadioGroupInjectionKey: InjectionKey<{
disabled: boolean;
value: RadioValue;
allowUncheck: boolean;
setValue: (value: RadioValue, context: { e: Event }) => void;
setValue: (value: RadioValue, context: { e: Event; name?: string }) => void;
}> = Symbol('RadioGroupProvide');

export const RadioButtonInjectionKey: InjectionKey<{}> = Symbol('RadioButtonProvide');
2 changes: 1 addition & 1 deletion src/radio/radio-group-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ export default {
return ['outline', 'primary-filled', 'default-filled'].includes(val);
},
},
/** 选中值发生变化时触发 */
/** 选中值发生变化时触发, `context.name` 指 RadioGroup 的 name 属性 */
onChange: Function as PropType<TdRadioGroupProps['onChange']>,
};
4 changes: 2 additions & 2 deletions src/radio/radio.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ size | String | medium | options: small/medium/large。Typescript:`SizeEnum`
value | String / Number / Boolean | - | `v-model` and `v-model:value` is supported。Typescript:`T` `type RadioValue = string \| number \| boolean`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/radio/type.ts) | N
defaultValue | String / Number / Boolean | - | uncontrolled property。Typescript:`T` `type RadioValue = string \| number \| boolean`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/radio/type.ts) | N
variant | String | outline | options: outline/primary-filled/default-filled | N
onChange | Function | | Typescript:`(value: T, context: { e: Event }) => void`<br/> | N
onChange | Function | | Typescript:`(value: T, context: { e: Event; name?:string }) => void`<br/> | N

### RadioGroup Events

name | params | description
-- | -- | --
change | `(value: T, context: { e: Event })` | \-
change | `(value: T, context: { e: Event; name?:string })` | \-
4 changes: 2 additions & 2 deletions src/radio/radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ size | String | medium | 组件尺寸【讨论中】。可选项:small/medium/
value | String / Number / Boolean | - | 选中的值。支持语法糖 `v-model` 或 `v-model:value`。TS 类型:`T` `type RadioValue = string \| number \| boolean`。[详细类型定义](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/radio/type.ts) | N
defaultValue | String / Number / Boolean | - | 选中的值。非受控属性。TS 类型:`T` `type RadioValue = string \| number \| boolean`。[详细类型定义](https://github.com/Tencent/tdesign-vue-next/tree/develop/src/radio/type.ts) | N
variant | String | outline | 单选组件按钮形式。可选项:outline/primary-filled/default-filled | N
onChange | Function | | TS 类型:`(value: T, context: { e: Event }) => void`<br/>选中值发生变化时触发 | N
onChange | Function | | TS 类型:`(value: T, context: { e: Event; name?:string }) => void`<br/>选中值发生变化时触发, `context.name` 指 RadioGroup 的 name 属性 | N

### RadioGroup Events

名称 | 参数 | 描述
-- | -- | --
change | `(value: T, context: { e: Event })` | 选中值发生变化时触发
change | `(value: T, context: { e: Event; name?:string })` | 选中值发生变化时触发, `context.name` 指 RadioGroup 的 name 属性
2 changes: 1 addition & 1 deletion src/radio/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({

if (radioGroup) {
const value = radioChecked.value && allowUncheck.value ? undefined : props.value;
radioGroup.setValue(value, { e });
radioGroup.setValue(value, { e, name: radioGroup.name });
} else {
const value = allowUncheck.value ? !radioChecked.value : true;
setInnerChecked(value, { e });
Expand Down
4 changes: 2 additions & 2 deletions src/radio/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export interface TdRadioGroupProps<T = RadioValue> {
*/
variant?: 'outline' | 'primary-filled' | 'default-filled';
/**
* 选中值发生变化时触发
* 选中值发生变化时触发, `context.name` 指 RadioGroup 的 name 属性
*/
onChange?: (value: T, context: { e: Event }) => void;
onChange?: (value: T, context: { e: Event; name?: string }) => void;
}

export type RadioOption = string | number | RadioOptionObj;
Expand Down
Loading