title: CheckboxGroup

sidebar_label: CheckboxGroup

Multi-item picker, consisting of multiple checkbox components.

Reference

Type

  1. ComponentType<CheckboxGroupProps>

Examples

  1. export default class PageCheckbox extends Component {
  2. state = {
  3. list: [
  4. {
  5. value: 'A',
  6. text: 'A',
  7. checked: false
  8. },
  9. {
  10. value: 'B',
  11. text: 'B',
  12. checked: true
  13. },
  14. {
  15. value: 'C',
  16. text: 'C',
  17. checked: false
  18. },
  19. {
  20. value: 'D',
  21. text: 'D',
  22. checked: false
  23. },
  24. {
  25. value: 'E',
  26. text: 'E',
  27. checked: false
  28. },
  29. {
  30. value: 'F',
  31. text: 'E',
  32. checked: false
  33. }
  34. ]
  35. }
  36. render () {
  37. return (
  38. <View className='page-body'>
  39. <View className='page-section'>
  40. <Text>default style</Text>
  41. <Checkbox value='selected' checked>Selected</Checkbox>
  42. <Checkbox style='margin-left: 20rpx' value='not-selected'>Not Selected</Checkbox>
  43. </View>
  44. <View className='page-section'>
  45. <Text>recommended style</Text>
  46. {this.state.list.map((item, i) => {
  47. return (
  48. <Label className='checkbox-list__label' for={i} key={i}>
  49. <Checkbox className='checkbox-list__checkbox' value={item.value} checked={item.checked}>{item.text}</Checkbox>
  50. </Label>
  51. )
  52. })}
  53. </View>
  54. </View>
  55. )
  56. }
  57. }

CheckboxGroupProps

Property Type Required Description
name string No The name is added to the form component as a key
onChange BaseEventOrigFunction<{{ value: string[]; }}> No The change event is triggered when the selected item in <CheckboxGroup/>is changed.

event.detail = {{ value: [An array of the values of the selected checkboxes.] }}

Property Support

Property WeChat Mini-Program H5 React Native
CheckboxGroupProps.name ✔️
CheckboxGroupProps.onChange ✔️ ✔️ ✔️

API Support

API WeChat Mini-Program H5 React Native
CheckboxGroup ✔️ ✔️ ✔️