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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Add focus method to Pivot.",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "v-hudole@microsoft.com"
}
15 changes: 13 additions & 2 deletions packages/office-ui-fabric-react/src/components/Pivot/Pivot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
BaseComponent,
KeyCodes,
css,
getId
getId,
createRef
} from '../../Utilities';
import { CommandButton } from '../../Button';
import { IPivotProps } from './Pivot.types';
Expand Down Expand Up @@ -42,6 +43,7 @@ export class Pivot extends BaseComponent<IPivotProps, IPivotState> {
private _keyToIndexMapping: { [key: string]: number };
private _keyToTabIds: { [key: string]: string };
private _pivotId: string;
private focusZone = createRef<FocusZone>();

constructor(props: IPivotProps) {
super(props);
Expand Down Expand Up @@ -89,6 +91,15 @@ export class Pivot extends BaseComponent<IPivotProps, IPivotState> {
});
}

/**
* Sets focus to the first pivot tab.
*/
public focus(): void {
if (this.focusZone.value) {
this.focusZone.value.focus();
}
}

public render() {
return (
<div>
Expand All @@ -103,7 +114,7 @@ export class Pivot extends BaseComponent<IPivotProps, IPivotState> {
*/
private _renderPivotLinks() {
return (
<FocusZone direction={ FocusZoneDirection.horizontal }>
<FocusZone componentRef={ this.focusZone } direction={ FocusZoneDirection.horizontal }>
<ul
className={ css('ms-Pivot', styles.root,
{ ['ms-Pivot--large ' + styles.rootIsLarge]: this.props.linkSize === PivotLinkSize.large },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { Pivot } from './Pivot';
import { PivotItem } from './PivotItem';

export interface IPivot {

/**
* Sets focus to the first pivot tab.
*/
focus(): void;
}

export interface IPivotProps extends React.Props<Pivot> {
Expand Down