diff --git a/src/components/picklist/PickList.js b/src/components/picklist/PickList.js index 0fb30371da..974f5efa1d 100644 --- a/src/components/picklist/PickList.js +++ b/src/components/picklist/PickList.js @@ -1,6 +1,6 @@ import React, { Component } from 'react' import PropTypes from 'prop-types'; -import { DomHandler, classNames } from '../utils/Utils'; +import { DomHandler, classNames, ObjectUtils } from '../utils/Utils'; import { PickListSubList } from './PickListSubList'; import { PickListControls } from './PickListControls'; import { PickListTransferControls } from './PickListTransferControls'; @@ -186,7 +186,9 @@ export class PickList extends Component { scrollInView(listContainer, direction = 1) { let selectedItems = listContainer.getElementsByClassName('p-highlight'); - DomHandler.scrollInView(listContainer, (direction === -1 ? selectedItems[0] : selectedItems[selectedItems.length - 1])); + if (ObjectUtils.isNotEmpty(selectedItems)) { + DomHandler.scrollInView(listContainer, (direction === -1 ? selectedItems[0] : selectedItems[selectedItems.length - 1])); + } } onSelectionChange(e, stateKey, callback) { @@ -197,10 +199,10 @@ export class PickList extends Component { this.setState({ [stateKey]: e.value }); } - if (this.state.sourceSelection && this.state.sourceSelection.length && stateKey === 'targetSelection') { + if (ObjectUtils.isNotEmpty(this.state.sourceSelection) && stateKey === 'targetSelection') { this.setState({ sourceSelection: [] }) } - else if (this.state.targetSelection && this.state.targetSelection.length && stateKey === 'sourceSelection') { + else if (ObjectUtils.isNotEmpty(this.state.targetSelection) && stateKey === 'sourceSelection') { this.setState({ targetSelection: [] }) } } diff --git a/src/components/picklist/PickListTransferControls.js b/src/components/picklist/PickListTransferControls.js index fe49fe0304..2301f0575b 100644 --- a/src/components/picklist/PickListTransferControls.js +++ b/src/components/picklist/PickListTransferControls.js @@ -16,7 +16,7 @@ export class PickListTransferControls extends Component { moveRight(event) { let selection = this.props.sourceSelection; - if (selection && selection.length) { + if (ObjectUtils.isNotEmpty(selection)) { let targetList = [...this.props.target]; let sourceList = [...this.props.source]; @@ -58,7 +58,7 @@ export class PickListTransferControls extends Component { moveLeft(event) { let selection = this.props.targetSelection; - if (selection && selection.length) { + if (ObjectUtils.isNotEmpty(selection)) { let targetList = [...this.props.target]; let sourceList = [...this.props.source]; @@ -100,10 +100,10 @@ export class PickListTransferControls extends Component { render() { - let moveRightDisabled = !this.props.sourceSelection.length; - let moveLeftDisabled = !this.props.targetSelection.length; - let moveAllRightDisabled = !this.props.source.length; - let moveAllLeftDisabled = !this.props.target.length; + let moveRightDisabled = ObjectUtils.isEmpty(this.props.sourceSelection); + let moveLeftDisabled = ObjectUtils.isEmpty(this.props.targetSelection); + let moveAllRightDisabled = ObjectUtils.isEmpty(this.props.source); + let moveAllLeftDisabled = ObjectUtils.isEmpty(this.props.target); let className = classNames('p-picklist-buttons p-picklist-transfer-buttons', this.props.className);