diff --git a/scss/components/form/_select.scss b/scss/components/form/_select.scss index 8e63eab0c..7cd7ccc1a 100644 --- a/scss/components/form/_select.scss +++ b/scss/components/form/_select.scss @@ -156,13 +156,17 @@ user-select: none; } - &-checkall { + &-checkAll { padding: ( $Form-select-menu-height - $Form-input-lineHeight * $Form-input-fontSize - px2rem(2px) )/2 $Form-select-paddingX; border-bottom: px2rem(1px) solid $Form-select-checkall-bottomBorder; min-width: px2rem(100px); + + label { + display: block; + } } &-option { @@ -187,10 +191,6 @@ background-color: $Form-select-menu-onDisabled-bg; } - &.is-checkAll { - border-bottom: px2rem(1px) solid $Form-select-checkall-bottomBorder; - } - &--placeholder { color: $Form-input-placeholderColor; } diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx index 47a1d5eb8..988667fbd 100644 --- a/src/components/Checkbox.tsx +++ b/src/components/Checkbox.tsx @@ -1,4 +1,3 @@ - /** * @file Checkbox * @author fex @@ -7,7 +6,7 @@ import * as React from 'react'; import * as cx from 'classnames'; import {ClassNamesFn, themeable} from '../theme'; -import { autobind } from '../utils/helper'; +import {autobind} from '../utils/helper'; const sizeMap = { sm: 'i-checks-sm', @@ -25,7 +24,6 @@ interface CheckboxProps { label?: string; className?: string; onChange?: (value: any) => void; - onClick?: (e:any, checked:boolean) => void; value?: any; containerClass?: string; inline?: boolean; @@ -58,25 +56,6 @@ export class Checkbox extends React.Component { onChange(e.currentTarget.checked ? trueValue : falseValue); } - @autobind - handleClick(e:any) { - const { - checked, - value, - trueValue, - onClick, - disabled - } = this.props; - - const isChecked:boolean = !!(typeof checked !== 'undefined' - ? checked - : typeof value === 'undefined' - ? value - : value == trueValue); - - disabled || onClick && onClick(e, isChecked); - } - render() { let { size, @@ -105,7 +84,6 @@ export class Checkbox extends React.Component { }, className )} - onClick={this.handleClick} > { input: HTMLInputElement; target: HTMLElement; + menu: React.RefObject = React.createRef(); constructor(props: SelectProps) { super(props); @@ -252,7 +253,11 @@ export class Select extends React.Component { }); } - toggle() { + toggle(e?: React.MouseEvent) { + if (e && this.menu.current && this.menu.current.contains(e.target as HTMLElement)) { + return; + } + this.props.disabled || this.setState({ isOpen: !this.state.isOpen, @@ -336,7 +341,7 @@ export class Select extends React.Component { } handleChange(selectItem: any) { - const {onChange, multiple, onNewOptionClick, checkAll} = this.props; + const {onChange, multiple, onNewOptionClick} = this.props; let {selection} = this.state; if (selectItem.isNew) { @@ -345,18 +350,14 @@ export class Select extends React.Component { } if (multiple) { - if (checkAll && selectItem.__all) { - this.toggleCheckAll(); + selection = selection.concat(); + const idx = selection.indexOf(selectItem); + if (~idx) { + selection.splice(idx, 1); } else { - selection = selection.concat(); - const idx = selection.indexOf(selectItem); - if (~idx) { - selection.splice(idx, 1); - } else { - selection.push(selectItem); - } - onChange(selection); + selection.push(selectItem); } + onChange(selection); } else { onChange(selectItem); } @@ -471,7 +472,6 @@ export class Select extends React.Component { if (multiple) { if (checkAll) { - filtedOptions.unshift({label: checkAllLabel, value: 'all', __all: true}); const optionsValues = options.map(option => option.value); const selectionValues = selection.map(select => select.value); checkedAll = optionsValues.every(option => selectionValues.indexOf(option) > -1); @@ -499,7 +499,18 @@ export class Select extends React.Component { } const menu = ( -
+
+ {multiple && checkAll ? ( +
+ + {checkAllLabel} + +
+ ) : null} {filtedOptions.length ? ( filtedOptions.map((item, index) => { const checked = checkAll ? selection.some((o:Option) => o.value == item.value) : false; @@ -515,31 +526,23 @@ export class Select extends React.Component { className={cx(`Select-option`, { 'is-disabled': item.disabled, 'is-highlight': highlightedIndex === index, - 'is-checkAll': checkAll && index === 0, 'is-active': selectedItem === item || (Array.isArray(selectedItem) && ~selectedItem.indexOf(item)), })} > - {checkAll ? - index === 0 ? ( - - {checkAllLabel} - - ) : ( - - {item.isNew - ? promptTextCreator(item.label as string) - : item.disabled - ? item[labelField] - : highlight(item[labelField], inputValue as string, cx('Select-option-hl'))} - + {checkAll ? ( + this.handleChange(item)} + > + {item.isNew + ? promptTextCreator(item.label as string) + : item.disabled + ? item[labelField] + : highlight(item[labelField], inputValue as string, cx('Select-option-hl'))} + ) : ( item.isNew ? promptTextCreator(item.label as string)