FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix tabs ref proptype by jschuler · Pull Request #2158 · patternfly/patternfly-react · GitHub

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

Filter by extension

Filter by extension .js  (2) .snap  (1) .ts  (2) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
    • Tab.d.ts
    • Tab.js
    • TabContent.d.ts
    • TabContent.js
      • Tabs.test.js.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface TabProps extends Omit<HTMLProps<HTMLDivElement>, 'id'> {
eventKey: number;
id?: string;
tabContentId?: string | number;
tabContentRef?: HTMLElement;
tabContentRef?: any;
title: string;
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,31 @@ const propTypes = {
/** child id for case in which a TabContent section is defined outside of a Tabs component */
tabContentId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
/** child reference for case in which a TabContent section is defined outside of a Tabs component */
tabContentRef: PropTypes.node,
forwardRef: PropTypes.node // purposefully not documented
tabContentRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.any }), PropTypes.string])
};

const defaultProps = {
children: null,
className: '',
href: null,
tabContentId: null,
tabContentRef: null,
forwardRef: undefined
tabContentRef: null
};

const withForwardedRef = Component => {
class TabContainer extends React.Component {
render() {
const { tabContentRef, ...rest } = this.props; // eslint-disable-line react/prop-types
return <Component ref={tabContentRef} {...rest} />;
const { forwardRef, ...rest } = this.props; // eslint-disable-line react/prop-types
return <Component ref={forwardRef} {...rest} />;
}
}
return React.forwardRef((props, tabContentRef) => <TabContainer {...props} forwardRef={tabContentRef} />);
};

class Tab extends React.Component {
render() {
// destructuring to prevent console warnings for applying eventKey, forwardRef, and tabContentId to a DOM element and remove title from the DOM element
const { children, eventKey, tabContentId, tabContentRef, forwardRef, title, ...props } = this.props;
// destructuring to prevent console warnings for applying eventKey, and tabContentId to a DOM element and remove title from the DOM element
const { children, eventKey, tabContentId, tabContentRef, title, ...props } = this.props;
const Component = props.href ? 'a' : 'button';
return (
<Component {...props} ref={tabContentRef}>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { FunctionComponent, HTMLProps } from 'react';

export interface TabContentProps extends HTMLProps<HTMLDivElement> {
'aria-label'?: string;
children?: any;
child?: React.ReactNode;
className?: string;
activeKey?: number;
eventKey?: number;
innerRef?: any;
id: string;
'aria-label'?: string;
}

declare const TabContent: FunctionComponent<TabContentProps>;
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const propTypes = {
/** uniquely identifies the controlling Tab if used outside Tabs component */
eventKey: PropTypes.number,
/** Callback for the section ref */
innerRef: PropTypes.func,
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.any }), PropTypes.string]),
/** id passed from parent to identify the content section */
id: PropTypes.string.isRequired,
/** title of controlling Tab if used outside Tabs component */
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ exports[`should call handleScrollButtons tabs with scrolls 1`] = `
aria-controls="pf-tab-section-0-tab1"
className="pf-c-tabs__button"
eventKey={0}
forwardRef={[Function]}
href={null}
id="tab1"
onClick={[Function]}
Expand Down Expand Up @@ -125,7 +124,6 @@ exports[`should call handleScrollButtons tabs with scrolls 1`] = `
aria-controls="pf-tab-section-1-tab2"
className="pf-c-tabs__button"
eventKey={1}
forwardRef={[Function]}
href={null}
id="tab2"
onClick={[Function]}
Expand Down Expand Up @@ -171,7 +169,6 @@ exports[`should call handleScrollButtons tabs with scrolls 1`] = `
aria-controls="pf-tab-section-2-tab3"
className="pf-c-tabs__button"
eventKey={2}
forwardRef={[Function]}
href={null}
id="tab3"
onClick={[Function]}
Expand Down Expand Up @@ -443,7 +440,6 @@ exports[`should call scrollLeft tabs with scrolls 1`] = `
aria-controls="pf-tab-section-0-tab1"
className="pf-c-tabs__button"
eventKey={0}
forwardRef={[Function]}
href={null}
id="tab1"
onClick={[Function]}
Expand Down Expand Up @@ -489,7 +485,6 @@ exports[`should call scrollLeft tabs with scrolls 1`] = `
aria-controls="pf-tab-section-1-tab2"
className="pf-c-tabs__button"
eventKey={1}
forwardRef={[Function]}
href={null}
id="tab2"
onClick={[Function]}
Expand Down Expand Up @@ -535,7 +530,6 @@ exports[`should call scrollLeft tabs with scrolls 1`] = `
aria-controls="pf-tab-section-2-tab3"
className="pf-c-tabs__button"
eventKey={2}
forwardRef={[Function]}
href={null}
id="tab3"
onClick={[Function]}
Expand Down Expand Up @@ -807,7 +801,6 @@ exports[`should call scrollRight tabs with scrolls 1`] = `
aria-controls="pf-tab-section-0-tab1"
className="pf-c-tabs__button"
eventKey={0}
forwardRef={[Function]}
href={null}
id="tab1"
onClick={[Function]}
Expand Down Expand Up @@ -853,7 +846,6 @@ exports[`should call scrollRight tabs with scrolls 1`] = `
aria-controls="pf-tab-section-1-tab2"
className="pf-c-tabs__button"
eventKey={1}
forwardRef={[Function]}
href={null}
id="tab2"
onClick={[Function]}
Expand Down Expand Up @@ -899,7 +891,6 @@ exports[`should call scrollRight tabs with scrolls 1`] = `
aria-controls="pf-tab-section-2-tab3"
className="pf-c-tabs__button"
eventKey={2}
forwardRef={[Function]}
href={null}
id="tab3"
onClick={[Function]}
Expand Down

Back | FazBrowse Home | New Git URL