Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-application-links] add onTabClick optional property to terra-application-links interface #2113

Merged
merged 9 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/terra-application-links/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* `onTabClick` property added to ApplicationLinks interface.

sPavl0v marked this conversation as resolved.
Show resolved Hide resolved
## 6.79.0 - (March 25, 2024)

* Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/terra-application-links/src/ApplicationLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const ApplicationLinksPropType = PropTypes.shape({
*/
icon: PropTypes.node,
})),
/**
* The click callback of the tab.
*/
onTabClick: PropTypes.func,
});

const ApplicationLinks = {
Expand Down
6 changes: 6 additions & 0 deletions packages/terra-application-links/src/tabs/ApplicationTabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const propTypes = {

icon: PropTypes.icon,
})),
/**
* The click callback of the tab.
*/
onTabClick: PropTypes.func,
/**
* The location as provided by the `withRouter()` HOC.
*/
Expand Down Expand Up @@ -150,6 +154,7 @@ class ApplicationTabs extends React.Component {
history,
staticContext,
hasIcons,
onTabClick,
...customProps
} = this.props;

Expand All @@ -165,6 +170,7 @@ class ApplicationTabs extends React.Component {
externalLink: link.externalLink,
icon: link.icon,
location,
onTabClick,
history,
};

Expand Down
4 changes: 3 additions & 1 deletion packages/terra-application-links/src/tabs/_Tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class ApplicationTab extends Component {

if (!this.isCurrentPath()) {
this.props.history.push(this.props.path);
} else if (this.props.onTabClick) {
}

if (this.props.onTabClick) {
this.props.onTabClick(event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ it('should render ApplicationTabs with links and alignment', () => {
expect(wrapper).toMatchSnapshot();
});

it('should render ApplicationTabs with links and alignment and onTabClick handler', () => {
const wrapper = enzyme.shallow(<div><ApplicationTabs links={testLinkConfig} alignment="start" onTabClick={() => {}} /></div>);
expect(wrapper).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test that onTabClick is called when clicking the tab and avoid using snapshots? Here is an example:

expect(handleOnClickOracle).toHaveBeenCalled();

});

it('should render ApplicationTabs with icons', () => {
const subject = (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,40 @@ exports[`should render ApplicationTabs with links and alignment 1`] = `
/>
</div>
`;

exports[`should render ApplicationTabs with links and alignment and onTabClick handler 1`] = `
<div>
<withRouter(ApplicationTabs)
alignment="start"
links={
Array [
Object {
"path": "/test1",
"text": "test 1",
},
Object {
"path": "/test2",
"text": "test 2",
},
Object {
"path": "/test3",
"text": "test 3",
},
Object {
"path": "/test4",
"text": "test 4",
},
Object {
"path": "/test5",
"text": "test 5",
},
Object {
"path": "/test6",
"text": "test 6",
},
]
}
onTabClick={[Function]}
/>
</div>
`;
Loading