Skip to content

Commit

Permalink
itemClick itemGroupClick参数传递原始数据对象
Browse files Browse the repository at this point in the history
  • Loading branch information
bplok20010 committed Feb 23, 2019
1 parent 4c574c1 commit 8a79fda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class ListBox extends React.Component {
labelInValue: false,
tabIndex: 0,
items: [],
emptyLabel: null,
emptyLabel: 'Not Found',
enableDownUpSelect: true,
onFocus: noop,
onBlur: noop,
Expand Down Expand Up @@ -367,14 +367,17 @@ export default class ListBox extends React.Component {
onDeselect={this.onItemDeselect}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
item={item}
>
{renderMenuItem ? renderMenuItem(item[labelField], item) : item[labelField]}
</ListItem>
) : (
<ListItemGroup
prefixCls={`${itemPrefixCls}-group`}
key={item[labelField]}
value={item[valueField]}
onClick={this.onItemGroupClick}
item={item}
label={renderMenuGroup ? renderMenuGroup(item[labelField], item) : item[labelField]}
>
{this.renderListItems(item[childrenField] || [], selectedMap)}
Expand Down Expand Up @@ -457,6 +460,10 @@ export default class ListBox extends React.Component {
this._indexValueMap = {};
this._activeIndex = null;

if (!items.length && !React.Children.count(children)) {
return emptyLabel;
}

const childs = items.length ?
this.renderListItems(items, selectedMap) :
this.renderListChild(children, selectedMap);
Expand Down
11 changes: 6 additions & 5 deletions src/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class ListItem extends React.Component {
onClick: PropTypes.func,
selected: PropTypes.bool,
disabled: PropTypes.bool,
item: PropTypes.object,
}

static defaultProps = {
Expand All @@ -31,22 +32,22 @@ export default class ListItem extends React.Component {
}

handleItemClick = (e) => {
const { onSelect, onDeselect, onClick, selected, disabled, value, children } = this.props;
const { onSelect, onDeselect, onClick, selected, disabled, value, children, item } = this.props;
if (disabled) return;

const item = {
const newItem = item || {
value,
label: children
};

if (onClick) {
onClick(item, e);
onClick(newItem, e);
}

if (!selected) {
onSelect && onSelect(item, this.refs.item)
onSelect && onSelect(newItem, this.refs.item)
} else {
onDeselect && onDeselect(item, this.refs.item)
onDeselect && onDeselect(newItem, this.refs.item)
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/ListItemGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class ItemGroup extends React.Component {
value: PropTypes.any,
children: PropTypes.node,
prefixCls: PropTypes.string,
onClick: PropTypes.func,
item: PropTypes.object,
}

static defaultProps = {
Expand All @@ -21,11 +23,13 @@ export default class ItemGroup extends React.Component {
const {
value,
label,
children
children,
onClick,
item
} = this.props;

if (onClick) {
onClick({
onClick(item || {
value, label, children
}, e);
}
Expand Down

0 comments on commit 8a79fda

Please sign in to comment.