Skip to content

Commit 9ecc5e1

Browse files
committed
feat: checkbox group support custom label
1 parent e13f4c5 commit 9ecc5e1

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

components/checkbox/Group.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ export default {
4444
},
4545
methods: {
4646
getOptions () {
47-
const { options } = this.$props
47+
const { options, $scopedSlots } = this
4848
return options.map(option => {
4949
if (typeof option === 'string') {
5050
return {
5151
label: option,
5252
value: option,
5353
}
5454
}
55-
return option
55+
let label = option.label
56+
if (label === undefined && $scopedSlots.label) {
57+
label = $scopedSlots.label(option)
58+
}
59+
return { ...option, label }
5660
})
5761
},
5862
toggleOption (option) {

components/checkbox/demo/group.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Generate a group of checkboxes from an array
1717
<br />
1818
<a-checkbox-group :options="options" :value="['Pear']" @change="onChange" />
1919
<br />
20-
<a-checkbox-group :options="optionsWithDisabled" disabled :defaultValue="['Apple']" @change="onChange" />
20+
<a-checkbox-group :options="optionsWithDisabled" disabled :defaultValue="['Apple']" @change="onChange">
21+
<span style="color: red" slot="label" slot-scope="{value}">{{value}}</span>
22+
</a-checkbox-group>
2123
</div>
2224
</template>
2325
<script>
@@ -28,7 +30,7 @@ const options = [
2830
{ label: 'Orange', value: 'Orange' },
2931
]
3032
const optionsWithDisabled = [
31-
{ label: 'Apple', value: 'Apple' },
33+
{ value: 'Apple' },
3234
{ label: 'Pear', value: 'Pear' },
3335
{ label: 'Orange', value: 'Orange', disabled: false },
3436
]

components/checkbox/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
| -------- | ----------- | ---- | ------- |
2424
| defaultValue | Default selected value | string\[] | \[] |
2525
| disabled | Disable all checkboxes | boolean | false |
26-
| options | Specifies options | string\[] \| Array&lt;{ label: string value: string disabled?: boolean, onChange?: function }> | \[] |
26+
| options | Specifies options, you can customize `label` with slot = "label" slot-scope = "option" | string\[] \| Array&lt;{ label: string value: string disabled?: boolean, onChange?: function }> | \[] |
2727
| value | Used for setting the currently selected value. | string\[] | \[] |
2828

2929
#### events

components/checkbox/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
| --- | --- | --- | --- |
2626
| defaultValue | 默认选中的选项 | string\[] | \[] |
2727
| disabled | 整组失效 | boolean | false |
28-
| options | 指定可选项 | string\[] \| Array&lt;{ label: string value: string disabled?: boolean, onChange?: function }> | \[] |
28+
| options | 指定可选项,可以通过 slot="label" slot-scope="option" 定制`label` | string\[] \| Array&lt;{ label: string value: string disabled?: boolean, onChange?: function }> | \[] |
2929
| value | 指定选中的选项 | string\[] | \[] |
3030

3131
#### 事件

0 commit comments

Comments
 (0)