Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/CommandBar/CommandBar.Props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as React from 'react';
import { IContextualMenuItem } from '../ContextualMenu/index';

export interface ICommandBar {
/**
* Sets focus to the active command in the list.
*/
focus(): void;
}

export interface ICommandBarProps extends React.HTMLProps<HTMLDivElement> {
/**
* Whether or not the search box is visible
Expand Down
11 changes: 8 additions & 3 deletions src/components/CommandBar/CommandBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { ICommandBarProps } from './CommandBar.Props';
import { ICommandBar, ICommandBarProps } from './CommandBar.Props';
import { FocusZone, FocusZoneDirection } from '../../FocusZone';
import { ContextualMenu, IContextualMenuItem } from '../../ContextualMenu';
import { EventGroup } from '../../utilities/eventGroup/EventGroup';
Expand All @@ -21,7 +21,7 @@ export interface ICommandBarState {
renderedFarItems?: IContextualMenuItem[];
}

export class CommandBar extends React.Component<ICommandBarProps, ICommandBarState> {
export class CommandBar extends React.Component<ICommandBarProps, ICommandBarState> implements ICommandBar {
public static defaultProps = {
items: [],
overflowItems: [],
Expand All @@ -34,6 +34,7 @@ export class CommandBar extends React.Component<ICommandBarProps, ICommandBarSta
farCommandSurface: HTMLElement;
commandBarRegion: HTMLElement;
searchSurface: HTMLElement;
focusZone: FocusZone;
};

private _id: string;
Expand Down Expand Up @@ -99,7 +100,7 @@ export class CommandBar extends React.Component<ICommandBarProps, ICommandBarSta
return (
<div className={ css('ms-CommandBar', className) } ref='commandBarRegion'>
{ searchBox }
<FocusZone direction={ FocusZoneDirection.horizontal } rootProps={ { role: 'menubar' } }>
<FocusZone ref='focusZone' direction={ FocusZoneDirection.horizontal } rootProps={ { role: 'menubar' } }>
<div className='ms-CommandBar-primaryCommands' ref='commandSurface'>
{ renderedItems.map((item, index) => (
this._renderItemInCommandBar(item, index, expandedMenuItemKey)
Expand Down Expand Up @@ -139,6 +140,10 @@ export class CommandBar extends React.Component<ICommandBarProps, ICommandBarSta
);
}

public focus() {
this.refs.focusZone.focus();
}

private _renderItemInCommandBar(item, index, expandedMenuItemKey, isFarItem?: boolean) {
const itemKey = item.key || index;
const className = item.onClick ? 'ms-CommandBarItem-link' : 'ms-CommandBarItem-text';
Expand Down