CommandBar: First Item In List Always Appears As Selected Item
Issue: Implement a command bar and add more than one child item to a top level item. Click the top level item and then select the second child item. Click the top level item again and observe the first child item shows it was selected.
Expected behavior: Implement a command bar and add more than one child item to a top level item. Click the top level item and then select the second child item. Click the top level item again and observe the second child item shows it was selected.
Code to replicate issue:
.commandBar i{
display: none;
}
const commandBarItems = this._generateCommandBarItems();
public render(): JSX.Element {
return (
<div className={styles.opportunityTracker}>
<div className={styles.container}>
{/* filter bar */}
<div className="ms-Grid-row">
<div className={css("ms-Grid-col ms-u-sm12", styles.commandBar)}>
<CommandBar
isSearchBoxVisible={ false }
searchPlaceholderText='Search...'
elipisisAriaLabel='More options'
items={ this.state["commandBarItems"] }
/>
</div>
</div>
private _generateCommandBarItems(): Array<IContextualMenuItem>{
const contextualMenuItems: Array<IContextualMenuItem> = [];
//Sort
contextualMenuItems.push({
key: 'Sort',
name: 'Sort',
icon: 'sortLines',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {ev.preventDefault();},
items: [
{
key: 'ALPHABETICAL',
name: 'ALPHABETICAL',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {
this.setState({
//replace setting the state with react add-ons update
//npm i react-addons-update
//let update = require{'react-addons-update'};
opportunities: this._sortAndFilterOpportunities(item.key, this.state["statusSelectedKey"], this.state["ownerSelectedKey"]),
sortedBySelectedKey: item.key
});
ev.preventDefault();
}
},
{
key: 'FORECAST DATE',
name: 'FORECAST DATE',
onClick: (item: IContextualMenuItem, ev: React.MouseEvent) : void => {
this.setState({
opportunities: this._sortAndFilterOpportunities(item.key, this.state["statusSelectedKey"], this.state["ownerSelectedKey"]),
sortedBySelectedKey: item.key
});
ev.preventDefault();
},
isChecked: true
}
]
});
I'd love to get a Designer's input here and see if this is intended.
@betrue-final-final (our Design guru in this case) states that the design intent is that the first item should not be in focus when it opens... let's look into this.
Any action needed on my end?
@TBag can you try this:
Wrap your app in a Fabric component.
<Fabric>
<App>
...stuff
<CommandBar ... />
</App>
</Fabric>
It should be focused, but you should only see the focus rect if you use the keyboard. This is globally controlled by the ms-Fabric.is-focusVisible class that the Fabric component adds at the right time (when the user is naving with the keyboard.)
@TBag ping; i'd like to make sure this solved your issue before closing.
@dzearing I have not had time to test it out but it's on our list. I'll let you know as soon as we try it out. Thanks for the suggestion to fix it.
Please let us know if there is an issue you're seeing.
For now I've created a codepen to illustrate the command bar usage. If you can repro the issue there that would be helpful.
http://codepen.io/dzearing/pen/ENjKPy