Skip to content

Commit

Permalink
feat(Tabs): Add domRef prop for getting the ref to the tabs DOM node (
Browse files Browse the repository at this point in the history
  • Loading branch information
danez authored Oct 5, 2017
1 parent 00a8401 commit e989491
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ Provide a custom class name for disabled tabs.
> This option can also be set directly at the `<Tab />` component.
#### domRef: `(node: ?HTMLElement) => void`
> default: `null`
Register a callback that will receive the underlying DOM node for every mount. It will also receive null on unmount.
#### forceRenderTabPanel: `boolean`
> default: `false`
Expand Down
1 change: 1 addition & 0 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Tabs extends Component {
defaultFocus: PropTypes.bool,
defaultIndex: PropTypes.number,
disabledTabClassName: PropTypes.string,
domRef: PropTypes.func,
forceRenderTabPanel: PropTypes.bool,
onSelect: onSelectPropType,
selectedIndex: selectedIndexPropType,
Expand Down
3 changes: 3 additions & 0 deletions src/components/UncontrolledTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class UncontrolledTabs extends Component {
children: childrenPropType,
className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]),
disabledTabClassName: PropTypes.string,
domRef: PropTypes.func,
focus: PropTypes.bool,
forceRenderTabPanel: PropTypes.bool,
onSelect: PropTypes.func.isRequired,
Expand Down Expand Up @@ -283,6 +284,7 @@ export default class UncontrolledTabs extends Component {
children, // unused
className,
disabledTabClassName, // unused
domRef,
focus, // unused
forceRenderTabPanel, // unused
onSelect, // unused
Expand All @@ -300,6 +302,7 @@ export default class UncontrolledTabs extends Component {
onKeyDown={this.handleKeyDown}
ref={node => {
this.node = node;
if (domRef) domRef(node);
}}
data-tabs
>
Expand Down
14 changes: 14 additions & 0 deletions src/components/__tests__/Tabs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe('<Tabs />', () => {
test('should accept className', () => {
expectToMatchSnapshot(createTabs({ className: 'foobar' }));
});

test('should accept domRef', () => {
let domNode;
mount(
createTabs({
domRef: node => {
domNode = node;
},
}),
);

expect(domNode).not.toBeUndefined();
expect(domNode.className).toBe('react-tabs');
});
});

describe('child props', () => {
Expand Down

0 comments on commit e989491

Please sign in to comment.