我正在使用NormalPeoplePicker
来自office-ui-fabric-react
. 我覆盖onRenderItem
了事件,但它破坏了 Persona 风格。我提供了两张图片和我的代码,感谢您的解决方案。
private onRenderItem(props: IPickerItemProps<IPersonaProps>):JSX.Element {
return (<div className={ "ms-FocusZone ms-PickerPersona-container personaContainer_894c3072" }>
<div className={ "ms-PickerItem-content itemContent_894c3072" }>
<Persona
{ ...props.item }
size={ PersonaSize.regular }
hidePersonaDetails={ false }
/>
</div>
<div className={ "ms-PickerItem-content itemContent_894c3072" }>
<IconButton
iconProps={{ iconName: 'Cancel' }}
title="Cancel"
ariaLabel="Cancel"
onClick={ () => { this.ListPeoplePicker_RemoveItem(props.index); } }
/>
</div>
</div>);
}
private ListPeoplePicker_RemoveItem(index: number) {
this.listPeoplePicker.items.splice(index, 1);
this.listPeoplePicker.forceUpdate();
}
return (
<div>
<NormalPeoplePicker
selectedItems={props.selectedItems}
onResolveSuggestions={onFilterChanged}
onRenderItem={onRenderItem}
//onEmptyInputFocus={returnMostRecentlyUsed}
getTextFromItem={getTextFromItem}
pickerSuggestionsProps={suggestionProps}
className={'ms-PeoplePicker text-300'}
key={'normal'}
// onValidateInput={validateInput}
removeButtonAriaLabel={'Remove'}
onItemSelected={onItemSelected}
onChange={onChange}
inputProps={{
placeholder: getPlaceholderText(),
onBlur: onBlur,
//onClick: (e) => { alert('click picker'); console.log(e, 'click pick') },
onFocus: (ev: React.FocusEvent<HTMLInputElement>) => {
setShowPlaceholder(true);
console.log('onFocus called')
},
'aria-label': 'People Picker',
}}
defaultSelectedItems={props.selectedItems}
componentRef={picker}
onInputChange={onInputChange}
resolveDelay={300}
disabled={isPickerDisabled}
styles={{ root: { width: 400, background: 'white' } }}
/>
</div>
);
原创风格:
我更改后的样式: