BasePicker: onBackspace call different function when delete item
Bug Report
- Package version(s): latest
Describe the issue:
- add several people in PeoplePicker
- press backscpace to delete the last person-> function removeItem in BasePicker will be called.
- use arrow key to set focus on the first added item -> function removeItems in BasePicker will be called.
I check the code in BasePicker onBackSpace:
// This is protected because we may expect the backspace key to work differently in a different kind of picker.
// This lets the subclass override it and provide it's own onBackspace. For an example see the BasePickerListBelow
protected onBackspace(ev: React.KeyboardEvent<HTMLElement>) {
if (this.state.items.length && !this.input.isValueSelected && this.input.cursorLocation === 0) {
if (this.selection.getSelectedCount() > 0) {
this.removeItems(this.selection.getSelection());
} else {
this.removeItem(this.state.items[this.state.items.length - 1]);
}
}
}
Why use if (this.selection.getSelectedCount() > 0) not if (this.selection.getSelectedCount() > 1)?
It there some other consideration?
Since getSelection() returns an array it was just easier to have removeItems called to iterate through. If you want it to be >1 then there would need be an if else statement since the current else statement removes the first item in the list.
I see. Thank you @joschect ! But I noticed something related to it.
removeItems() function does not call onChange() —— and it actually changes the selected person in the list. I think it might be a bug. It will not call the props passed by user when the list is changed.
protected removeItem(item: IPickerItemProps<T>) {
...
this.setState({ items: newItems }, () => this.onChange());
}
protected removeItems(itemsToRemove: any[]) {
...
this.setState({ items: newItems }, () => this.resetFocus(index));
}
@MirandaGe Good Catch! That is definitely a bug.
Issue has been fixed and merged. Updating the status.