Office UI Fabric - PeoplePicker:无法让 createGenericItem 工作

Office UI Fabric - PeoplePicker: Cannot get createGenericItem to work

也许这只是我的一个误会,但我认为PeoplePicker(https://developer.microsoft.com/en-us/fabric#/components/peoplepicker)中createGenericItem的回调用于处理输入,无法与任何可用的匹配项目,然后可以为此创建一个临时项目。但是,无论我尝试什么,都不会调用回调。

针对这个问题,我在这里做了一个简单的笔:https://codepen.io/anon/pen/daGPWe?editors=0010

在示例中,有两个项目,Peter 和 Maria。如果您键入不同的内容(然后按 Enter、Tab、space,随便什么),我希望 createGenericItem 回调被调用,但事实并非如此。

我做错了什么?还是对这个回调的目的有误解?我无法在任何地方找到示例。

关于

but I thought the callback for createGenericItem in the PeoplePicker (https://developer.microsoft.com/en-us/fabric#/components/peoplepicker) was used to handle input

没错。为了触发IBasePickerProps.createGenericItem函数,IBasePickerProps.onValidateInput函数需要提供ValidationState.valid作为return值,例如:

<NormalPeoplePicker
      createGenericItem={this.createGenericItem}
      onValidateInput={this.handleValidateInput}
      selectedItems={this.state.selectedItems}
      onResolveSuggestions={this.handleResolveSuggestions}
      onChange={this.handleChange}
/>


private handleValidateInput(input: string) {
   return ValidationState.valid;
}

private createGenericItem(input: string, validationState: ValidationState) {
   return { text: "Unknown person",  state: validationState };
}

This demo 演示它,一旦单击 tabenter 键并且无法将值解析为任何可用项目,就会显示 Unknown person 项目