-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Pivot: render headers only #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
890b261
a61b260
587cff4
dc2f3b2
f7faae2
cb7e9ea
94c79b2
ed66d14
b7983b6
b6d223f
4c1b45c
95af888
f480b67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "changes": [ | ||
| { | ||
| "packageName": "office-ui-fabric-react", | ||
| "comment": "Pivot: new props headersOnly and getTabId.", | ||
| "type": "minor" | ||
| }, | ||
| { | ||
| "comment": "", | ||
| "packageName": "@uifabric/utilities", | ||
| "type": "none" | ||
| }, | ||
| { | ||
| "comment": "", | ||
| "packageName": "@uifabric/example-app-base", | ||
| "type": "none" | ||
| } | ||
| ], | ||
| "email": "v-panu@microsoft.com" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,18 @@ export interface IPivotProps extends React.Props<Pivot> { | |
| */ | ||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels like ideally we would split the component into a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I started thinking like you, but then I realized that using the So my opinion is that we don't need extra complexity, we can just demonstrate with the example how this can be easily achieved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to close this up and put a backlog item in for splitting these up? Or is there still work being done on this PR?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ready from my side. |
||
|
|
||
| /** | ||
| * 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 { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<any, any> { | ||
| state = { selectedKey: 'rectangleRed' }; | ||
|
|
||
| public render() { | ||
| return ( | ||
| <div> | ||
| <div | ||
| aria-labelledby={ this._getTabId(this.state.selectedKey) } | ||
| role="tabitem" | ||
| style={ { | ||
| float: 'left', | ||
| width: 100, | ||
| height: this.state.selectedKey === 'squareRed' ? 100 : 200, | ||
| background: this.state.selectedKey === 'rectangleGreen' ? 'green' : 'red' | ||
| } } /> | ||
| <Pivot | ||
| selectedKey={ this.state.selectedKey } | ||
| onLinkClick={ this._handleLinkClick } | ||
| headersOnly={ true } | ||
| getTabId={ this._getTabId }> | ||
| <PivotItem linkText='Rectangle red' itemKey='rectangleRed' /> | ||
| <PivotItem linkText='Square red' itemKey='squareRed' /> | ||
| <PivotItem linkText='Rectangle green' itemKey='rectangleGreen' /> | ||
| </Pivot> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| @autobind | ||
| private _handleLinkClick(item: PivotItem): void { | ||
| this.setState({ | ||
| selectedKey: item.props.itemKey | ||
| }); | ||
| } | ||
|
|
||
| @autobind | ||
| private _getTabId(itemKey: string): string { | ||
| return `ShapeColorPivot_${itemKey}`; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something along the lines of "Pivot: Allow rendering PivotItem headers without content"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.