简体   繁体   中英

How To Get New Persona Behavior in PeoplePicker

The documentation allows you to enter any string, hit [Tab] and it will display it as a persona. Trying to replicate this behavior, but am having trouble and the sample code says nothing.

我想要的行为

https://developer.microsoft.com/en-us/fabric#/components/peoplepicker

My PeoplePicker:

<CompactPeoplePicker
    getTextFromItem={(item) => { return item.text; } }
    onItemSelected={(item) => {
        console.log(item);
        return new Promise((resolve, reject) => {
            resolve(item);
        })
    }}
    selectedItems={this.state.currentSelectedItems}
    onChange={(items) => { 
        console.log(items);
        this.setState({ currentSelectedItems: items}); 
    }}
    onResolveSuggestions={this._onResolveSuggestions}
    className={'ms-PeoplePicker'} 
    pickerSuggestionsProps={{
        suggestionsHeaderText: 'Suggested People',
        mostRecentlyUsedHeaderText: 'Suggested Contacts',
        noResultsFoundText: 'No results found',
        loadingText: 'Loading',
        showRemoveButtons: true,
        suggestionsAvailableAlertText: 'People Picker Suggestions available',
        suggestionsContainerAriaLabel: 'Suggested contacts'
    }}
/>

我得到的行为

The answer is to simply return a new Persona as part of onResolveSuggestions

_onResolveSuggestions = (filterText, ...) => {
    var suggestions = ...;
    suggestions.splice(0, 0, { name: filterText, text: filterText });
    return suggestions;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM