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

添加 RadioGroup 组件的 cancelable 属性,支持取消选中功能 #541

Open
wants to merge 2 commits into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/pages/radio/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@
</wd-radio-group>
</demo-block>

<demo-block title="可取消选中" transparent>
<wd-radio-group v-model="value4" cell shape="button" cancelable>
<wd-radio :value="1">选项一</wd-radio>
<wd-radio :value="2">选项二</wd-radio>
<wd-radio :value="3">选项三</wd-radio>
<wd-radio :value="4">选项四</wd-radio>
<wd-radio :value="5">选项五</wd-radio>
<wd-radio :value="6">选项六</wd-radio>
<wd-radio :value="7">选项七</wd-radio>
</wd-radio-group>
</demo-block>

<demo-block title="同行展示">
<wd-radio-group v-model="value5" inline>
<wd-radio :value="1">单选框1</wd-radio>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type RadioGroupProvide = {
cell?: boolean
size?: string
inline?: boolean
cancelable?: boolean
}
updateValue: (value: string | number | boolean) => void
}
Expand All @@ -32,5 +33,7 @@ export const radioGroupProps = {
/** 设置大小,默认为空 */
size: makeStringProp(''),
/** 同行展示,默认为 false */
inline: makeBooleanProp(false)
inline: makeBooleanProp(false),
/** 是否可取消选中,默认为 false */
cancelable: makeBooleanProp(false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ watch(
* @description 处理radio子节点通知
*/
function updateValue(value: string | number | boolean) {
emit('update:modelValue', value)
if (props.cancelable && props.modelValue === value) {
emit('update:modelValue', '')
} else {
emit('update:modelValue', value)
}
emit('change', {
value
})
Expand Down