diff --git a/common/changes/pivotHeadersOnly_2017-04-07-10-40.json b/common/changes/pivotHeadersOnly_2017-04-07-10-40.json new file mode 100644 index 0000000000000..e9407978e6d2d --- /dev/null +++ b/common/changes/pivotHeadersOnly_2017-04-07-10-40.json @@ -0,0 +1,20 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "Pivot: Allow rendering PivotItem headers without content.", + "type": "minor" + }, + { + "comment": "", + "packageName": "@uifabric/utilities", + "type": "none" + }, + { + "comment": "", + "packageName": "@uifabric/example-app-base", + "type": "none" + } + ], + "email": "v-panu@microsoft.com" +} diff --git a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.Props.ts b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.Props.ts index e6dcf8c72a510..df53f832a8337 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.Props.ts +++ b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.Props.ts @@ -50,6 +50,18 @@ export interface IPivotProps extends React.Props { */ linkFormat?: PivotLinkFormat; + /** + * Specify whether to skip rendering the tabpanel with the content of the selected tab. + * Use this prop if you plan to separately render the tab content + * and don't want to leave an empty tabpanel in the page that may confuse Screen Readers. + */ + headersOnly?: boolean; + + /** + * Optional. Specify how IDs are generated for each tab header. + * Useful if you're rendering content outside and need to connect aria-labelledby. + */ + getTabId?: (itemKey: string, index: number) => string; } export enum PivotLinkFormat { diff --git a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.tsx b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.tsx index 497eee7845026..ccb955e0cf8be 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/Pivot.tsx +++ b/packages/office-ui-fabric-react/src/components/Pivot/Pivot.tsx @@ -27,7 +27,7 @@ const styles: any = stylesImport; * * * - * + * * * */ @@ -170,6 +170,10 @@ export class Pivot extends BaseComponent { * Renders the current Pivot Item */ private _renderPivotItem() { + if (this.props.headersOnly) { + return null; + } + const itemKey: string = this.state.selectedKey; const index = this._keyToIndexMapping[itemKey]; let { selectedTabId } = this.state; @@ -206,13 +210,24 @@ export class Pivot extends BaseComponent { onRenderItemLink: pivotItem.props.onRenderItemLink }); this._keyToIndexMapping[itemKey] = index; - this._keyToTabIds[itemKey] = this._pivotId + `-Tab${index}`; + this._keyToTabIds[itemKey] = this.getTabId(itemKey, index); } }); return links; } + /** + * Generates the Id for the tab button. + */ + private getTabId(itemKey: string, index: number): string { + if (this.props.getTabId) { + return this.props.getTabId(itemKey, index); + } + + return this._pivotId + `-Tab${index}`; + } + /** * whether the key exists in the pivot items. */ diff --git a/packages/office-ui-fabric-react/src/components/Pivot/PivotPage.tsx b/packages/office-ui-fabric-react/src/components/Pivot/PivotPage.tsx index c56311ff58731..6541fab6c0508 100644 --- a/packages/office-ui-fabric-react/src/components/Pivot/PivotPage.tsx +++ b/packages/office-ui-fabric-react/src/components/Pivot/PivotPage.tsx @@ -14,6 +14,7 @@ import { PivotFabricExample } from './examples/Pivot.Fabric.Example'; import { PivotOnChangeExample } from './examples/Pivot.OnChange.Example'; import { PivotRemoveExample } from './examples/Pivot.Remove.Example'; import { PivotOverrideExample } from './examples/Pivot.Override.Example'; +import { PivotSeparateExample } from './examples/Pivot.Separate.Example'; const PivotRemoveExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.Remove.Example.tsx') as string; const PivotBasicExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.Basic.Example.tsx') as string; @@ -24,6 +25,7 @@ const PivotFabricExampleCode = require('!raw-loader!office-ui-fabric-react/src/c const PivotOnChangeExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.OnChange.Example.tsx') as string; const PivotIconCountExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.IconCount.Example.tsx') as string; const PivotOverrideExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.Override.Example.tsx') as string; +const PivotSeparateExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/Pivot/examples/Pivot.Separate.Example.tsx') as string; export class PivotPage extends React.Component { public render() { @@ -60,6 +62,9 @@ export class PivotPage extends React.Component { + + + } propertiesTables={ diff --git a/packages/office-ui-fabric-react/src/components/Pivot/examples/Pivot.Separate.Example.tsx b/packages/office-ui-fabric-react/src/components/Pivot/examples/Pivot.Separate.Example.tsx new file mode 100644 index 0000000000000..7736a8b36e1ce --- /dev/null +++ b/packages/office-ui-fabric-react/src/components/Pivot/examples/Pivot.Separate.Example.tsx @@ -0,0 +1,46 @@ +import * as React from 'react'; +import { Label } from 'office-ui-fabric-react/lib/Label'; +import { Button } from 'office-ui-fabric-react/lib/Button'; +import { Pivot, PivotItem } from 'office-ui-fabric-react/lib/Pivot'; +import { autobind } from 'office-ui-fabric-react/lib/Utilities'; + +export class PivotSeparateExample extends React.Component { + public state = { selectedKey: 'rectangleRed' }; + + public render() { + return ( +
+
+ + + + + +
+ ); + } + + @autobind + private _handleLinkClick(item: PivotItem): void { + this.setState({ + selectedKey: item.props.itemKey + }); + } + + @autobind + private _getTabId(itemKey: string): string { + return `ShapeColorPivot_${itemKey}`; + } +}