Retrieves all accounts and allows account selection through dropdown and search. To capture the currently selected account, you can use the onChange
listener.
Note that the platform already contains its own account picker, which is located in the header of it. This one can be configured to be shown using the nerdlet.setConfig
API (passing { accountPicker: true }
), and its value can be read using <PlatformStateContext.Consumer>
. For full reference, please check these APIs.
Usage
import { AccountPicker } from 'nr1'
Examples
Basic
class Example extends React.Component { constructor() { super(...arguments);
this.state = { accountId: null };
this.onChangeAccount = this.onChangeAccount.bind(this); }
onChangeAccount(_, value) { alert(`Selected account: ${value}`);
this.setState({ accountId: value }); }
render() { return ( <AccountPicker value={this.state.accountId} onChange={this.onChangeAccount} /> ); }}
With inline label
class Example extends React.Component { constructor() { super(...arguments);
this.state = { accountId: null };
this.onChangeAccount = this.onChangeAccount.bind(this); }
onChangeAccount(_, value) { alert(`Selected account: ${value}`);
this.setState({ accountId: value }); }
render() { return ( <AccountPicker label="Account" labelInline value={this.state.accountId} onChange={this.onChangeAccount} /> ); }}
Props
string | Provide a descriptive label for this control, e.g. "Accounts". |
string | Appends class names to the component.Should be used only for positioning and spacing purposes. |
boolean | Shows an option at the top named "All accounts". When selected, the value provided by the |
boolean | If |
string | Text to display as label. |
boolean | Display the label inline the form control.Use only when the component is not inside a |
function | Callback fired every time the user clicks an account from the list.
Id of the account selected. |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like |
object | Inline style for custom styling.Should be used only for positioning and spacing purposes. |
string | Adds a |
number|enum | Id of the selected account. |