From a88e583282e63de59e9fec171323fbf611c3cff4 Mon Sep 17 00:00:00 2001 From: GanNing Date: Fri, 23 Aug 2019 04:27:02 +0800 Subject: [PATCH] fix(checkbox): Replace "idx" with "option" as the parameter for the click event We use "value" as the key of the option. When "value" has not changed, but the order of the options changes, the option will not be re-rendered, resulting in an error in the "idx" parameter of the click event. --- src/components/checkbox/index.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/checkbox/index.js b/src/components/checkbox/index.js index 93d064183..957669789 100644 --- a/src/components/checkbox/index.js +++ b/src/components/checkbox/index.js @@ -5,9 +5,8 @@ import classNames from 'classnames' import AtComponent from '../../common/component' export default class AtCheckbox extends AtComponent { - handleClick (idx) { - const { selectedList, options } = this.props - const option = options[idx] + handleClick (option) { + const { selectedList } = this.props const { disabled, value } = option if (disabled) return @@ -31,14 +30,13 @@ export default class AtCheckbox extends AtComponent { const rootCls = classNames('at-checkbox', className) return - { options.map((option, idx) => { + { options.map(option => { const { value, disabled, label, desc } = option const optionCls = classNames('at-checkbox__option', { 'at-checkbox__option--disabled': disabled, 'at-checkbox__option--selected': selectedList.includes(value) }) - - return + return