-
Notifications
You must be signed in to change notification settings - Fork 380
Add Support for disabled state tabs #6261
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 all commits
0e6bba0
e5a3eaa
5d2959e
3d11d93
1ce0b00
f74d237
4e05b21
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 |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import { PickOptional } from '../../helpers/typeUtils'; | |
| import AngleLeftIcon from '@patternfly/react-icons/dist/esm/icons/angle-left-icon'; | ||
| import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon'; | ||
| import { getUniqueId, isElementInView, formatBreakpointMods } from '../../helpers/util'; | ||
| import { TabButton } from './TabButton'; | ||
| import { TabContent } from './TabContent'; | ||
| import { TabProps } from './Tab'; | ||
| import { TabsContextProvider } from './TabsContext'; | ||
|
|
@@ -113,9 +112,10 @@ export class Tabs extends React.Component<TabsProps, TabsState> { | |
| handleTabClick( | ||
| event: React.MouseEvent<HTMLElement, MouseEvent>, | ||
| eventKey: number | string, | ||
| tabContentRef: React.RefObject<any>, | ||
| mountOnEnter: boolean | ||
| tabContentRef: React.RefObject<any> | ||
| ) { | ||
| // When tab is an achor tag with href, cancel navigation event | ||
| event.preventDefault(); | ||
| const { shownKeys } = this.state; | ||
| const { onSelect, defaultActiveKey } = this.props; | ||
| // if defaultActiveKey Tabs are uncontrolled, set new active key internally | ||
|
|
@@ -138,7 +138,7 @@ export class Tabs extends React.Component<TabsProps, TabsState> { | |
| tabContentRef.current.hidden = false; | ||
| } | ||
| } | ||
| if (mountOnEnter) { | ||
| if (this.props.mountOnEnter) { | ||
| this.setState({ | ||
| shownKeys: shownKeys.concat(eventKey) | ||
| }); | ||
|
|
@@ -274,7 +274,16 @@ export class Tabs extends React.Component<TabsProps, TabsState> { | |
| const localActiveKey = defaultActiveKey !== undefined ? uncontrolledActiveKey : activeKey; | ||
|
|
||
| return ( | ||
| <TabsContextProvider value={{ variant }}> | ||
| <TabsContextProvider | ||
| value={{ | ||
| variant, | ||
| mountOnEnter, | ||
| unmountOnExit, | ||
| localActiveKey, | ||
| uniqueId, | ||
| handleTabClick: (...args) => this.handleTabClick(...args) | ||
| }} | ||
| > | ||
| <Component | ||
| aria-label={ariaLabel} | ||
| className={css( | ||
|
|
@@ -303,46 +312,7 @@ export class Tabs extends React.Component<TabsProps, TabsState> { | |
| <AngleLeftIcon /> | ||
| </button> | ||
| <ul className={css(styles.tabsList)} ref={this.tabList} onScroll={this.handleScrollButtons}> | ||
| {filteredChildren.map((child, index) => { | ||
| const { | ||
| title, | ||
| eventKey, | ||
| tabContentRef, | ||
| id: childId, | ||
| tabContentId, | ||
| className: childClassName = '', | ||
| ouiaId: childOuiaId, | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| isHidden, | ||
| ...rest | ||
| } = child.props; | ||
| let ariaControls = tabContentId ? `${tabContentId}` : `pf-tab-section-${eventKey}-${childId || uniqueId}`; | ||
| if ((mountOnEnter || unmountOnExit) && eventKey !== localActiveKey) { | ||
| ariaControls = undefined; | ||
| } | ||
| return ( | ||
| <li | ||
| key={index} | ||
| className={css( | ||
| styles.tabsItem, | ||
| eventKey === localActiveKey && styles.modifiers.current, | ||
| childClassName | ||
| )} | ||
| > | ||
| <TabButton | ||
| className={css(styles.tabsLink)} | ||
| onClick={(event: any) => this.handleTabClick(event, eventKey, tabContentRef, mountOnEnter)} | ||
| id={`pf-tab-${eventKey}-${childId || uniqueId}`} | ||
| aria-controls={ariaControls} | ||
| tabContentRef={tabContentRef} | ||
| ouiaId={childOuiaId} | ||
| {...rest} | ||
| > | ||
| {title} | ||
| </TabButton> | ||
| </li> | ||
| ); | ||
| })} | ||
| {filteredChildren} | ||
|
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. I'm a little confused why this mapping is no longer needed, did the structure of
Contributor
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. The tab component used to return null, i.e. render nothing. So filtered children was just an array of objects. I needed a ref on the tab component for tooltips, so I had to forward ref and render an instance to attach a ref to. |
||
| </ul> | ||
| <button | ||
| className={css(styles.tabsScrollButton, isSecondary && buttonStyles.modifiers.secondary)} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.