Data Binding

The DropDownButton enables you to bind it to an array of strings, an array of objects, or DropDownButtonItem child components.

Arrays of Strings

The following example demonstrates how to bind the DropDownButton to an array of strings.

const items=['My Profile', 'Friend Requests', 'Account Settings', 'Support', 'Log Out'];
class App extends React.Component {
    render() {
        return (
            <div>
                <DropDownButton items={items} text="User Settings" />
            </div>
        );
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
)

Arrays of Objects

When the DropDownButton is bound to an array of objects, the component extracts the text value from the data items and, in this way, sets the text of the items in the popup. If the text field in the data objects is named text, the component gets its value automatically. However, if the name of the property in the data source is different—for example, actionText—you have to set it to the textField property of the DropDownButton.

For a list of all fields the items model uses, refer to the article on the ButtonItem configuration.

const items=[{
        actionName: 'Undo', icon: 'undo',
    }, {
        actionName: 'Redo', icon: 'redo', disabled: true
    }, {
        actionName: 'Cut', icon: 'cut'
    }, {
        actionName: 'Copy', icon: 'copy'
    }, {
        actionName: 'Paste', icon: 'paste'
}];
class App extends React.Component {
    render() {
        return (
            <div>
                <DropDownButton textField="actionName" items={items} text="Edit" />
            </div>
        );
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
)

Child Components

The following example demonstrates how to use the DropDownButtonItem child components to populate the popup items.

class App extends React.Component {
    render() {
        return (
            <div>
                <DropDownButton text="Edit">
                    <DropDownButtonItem text="Undo" icon="undo" />
                    <DropDownButtonItem text="Redo" icon="redo" disabled={true} />
                    <DropDownButtonItem text="Cut" icon="cut" />
                    <DropDownButtonItem text="Copy" icon="copy" />
                    <DropDownButtonItem text="Paste" icon="paste" />
                </DropDownButton>
            </div>
        );
    }
}
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
)
 /