fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

CommandBar: First Item In List Always Appears As Selected Item

Open TBag opened this issue 10 years ago • 7 comments

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
        }
      ]
    });
command bar first item always selected

TBag avatar Oct 05 '16 14:10 TBag

I'd love to get a Designer's input here and see if this is intended.

ericthompson avatar Oct 21 '16 20:10 ericthompson

@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.

ericthompson avatar Oct 21 '16 21:10 ericthompson

Any action needed on my end?

TBag avatar Oct 24 '16 11:10 TBag

@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.)

dzearing avatar Oct 24 '16 18:10 dzearing

@TBag ping; i'd like to make sure this solved your issue before closing.

dzearing avatar Oct 27 '16 16:10 dzearing

@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.

TBag avatar Oct 27 '16 18:10 TBag

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

dzearing avatar Nov 07 '16 19:11 dzearing