fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

BasePicker: onBackspace call different function when delete item

Open MirandaGe opened this issue 9 years ago • 4 comments

Bug Report

  • Package version(s): latest

Describe the issue:

  1. add several people in PeoplePicker
  2. press backscpace to delete the last person-> function removeItem in BasePicker will be called.
  3. 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?

MirandaGe avatar Mar 08 '17 01:03 MirandaGe

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.

joschect avatar Mar 09 '17 16:03 joschect

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 avatar Mar 13 '17 08:03 MirandaGe

@MirandaGe Good Catch! That is definitely a bug.

joschect avatar Mar 14 '17 16:03 joschect

Issue has been fixed and merged. Updating the status.

gitjain avatar Mar 31 '17 21:03 gitjain