let { DefaultButton, SearchBox, Icon, IContextualMenuListProps, IContextualMenuItem, IRenderFunction, Fabric } = window.Fabric; const ITEMS: IContextualMenuItem[] = [ { key: 'newItem', text: 'New', onClick: () => console.log('New clicked') }, { key: 'rename', text: 'Rename', onClick: () => console.log('Rename clicked') }, { key: 'edit', text: 'Edit', onClick: () => console.log('Edit clicked') }, { key: 'properties', text: 'Properties', onClick: () => console.log('Properties clicked') }, { key: 'linkNoTarget', text: 'Link same window', href: 'http://bing.com' }, { key: 'linkWithTarget', text: 'Link new window', href: 'http://bing.com', target: '_blank' }, { key: 'linkWithOnClick', name: 'Link click', href: 'http://bing.com', onClick: (ev: React.MouseEvent) => { alert('Link clicked'); ev.preventDefault(); }, target: '_blank' }, { key: 'disabled', text: 'Disabled item', disabled: true, onClick: () => console.error('Disabled item should not be clickable.') } ]; class ContextualMenuWithCustomMenuListExample extends React.Component< {}, { items: IContextualMenuItem[]; } > { constructor(props: {}) { super(props); this._renderMenuList = this._renderMenuList.bind(this); this._onAbort = this._onAbort.bind(this); this._onChange = this._onChange.bind(this); this.state = { items: ITEMS }; } public render(): JSX.Element { return (
); } private _onAbort() { this.setState({ items: ITEMS }); } private _onChange(newValue: any) { const filteredItems = ITEMS.filter(item => item.text && item.text.toLowerCase().includes(newValue.toLowerCase())); if (!filteredItems || !filteredItems.length) { filteredItems.push({ key: 'no_results', onRender: (item, dismissMenu) => (
No actions found
) }); } this.setState((prevState, props) => ({ items: filteredItems })); } private _renderMenuList( menuListProps: IContextualMenuListProps, defaultRender: IRenderFunction ) { return (
{defaultRender(menuListProps)}
); } } ReactDOM.render(, document.getElementById('content'));