Skip to content

Commit

Permalink
Fix primefaces#2418: TabPanel add onTabClose event
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 27, 2021
1 parent 8461882 commit a57014c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/tabview/TabView.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ interface TabViewTabChangeParams {
index: number;
}

interface TabViewTabCloseParams {
originalEvent: React.SyntheticEvent;
index: number;
}

export interface TabViewProps {
id?: string;
activeIndex?: number;
Expand All @@ -46,6 +51,7 @@ export interface TabViewProps {
renderActiveOnly?: boolean;
scrollable?: boolean;
onTabChange?(e: TabViewTabChangeParams): void;
onTabClose?(e: TabViewTabCloseParams): void;
}

// tslint:disable-next-line:max-classes-per-file
Expand Down
6 changes: 6 additions & 0 deletions src/components/tabview/TabView.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class TabView extends Component {
className: null,
renderActiveOnly: true,
onTabChange: null,
onTabClose: null,
scrollable: false
}

Expand All @@ -56,6 +57,7 @@ export class TabView extends Component {
className: PropTypes.string,
renderActiveOnly: PropTypes.bool,
onTabChange: PropTypes.func,
onTabClose: PropTypes.func,
scrollable: PropTypes.bool
};

Expand Down Expand Up @@ -111,6 +113,10 @@ export class TabView extends Component {
tabInfo && this.onTabHeaderClick(event, tabInfo.tab, tabInfo.index);
});

if (this.props.onTabClose) {
this.props.onTabClose({ originalEvent: event, index: index });
}

event.preventDefault();
}

Expand Down
7 changes: 7 additions & 0 deletions src/showcase/tabview/TabViewDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,13 @@ template: (options) => {
</td>
<td>Callback to invoke when an active tab is changed.</td>
</tr>
<tr>
<td>onTabClose</td>
<td>event.originalEvent: Browser event <br />
event.index: Index of the selected tab
</td>
<td>Callback to invoke when a tab is closed.</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit a57014c

Please sign in to comment.