Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
Close all tabs from Tabpane in reactjs

I use antd library for creating a tab section. The problem that I have is to close all tabs that are opened on clicking a button 'close all tabs'. But onClicking each time only last opened tab is being closed.

I have two useStates...focusingPaneKey denotes the tab which is active. openingPaneKeys is an array of all the active tabs.

On clicking the button handleTabsEdit method is called, which again will call closePane method.

const handleTabsEdit = useCallback((key, action) => {
if (action === 'remove') {
  closePane(key)
}
}, [closePane])


const closePane = (paneKey) => {
if (paneKey === focusingPaneKey) {
  const paneKeyIndex = openingPaneKeys.indexOf(paneKey)
  setFocusingPaneKey(openingPaneKeys[paneKeyIndex - 1])
}
setOpeningPaneKeys(openingPaneKeys.filter((openingPaneKey) => 
openingPaneKey !== paneKey))
}


return(
  <Button onClick={() => openingPaneKeys.forEach
  (id => this.handleTabsEdit(id, 'remove'))}>Close All Tabs</Button>
)

 const panes = {
 1: { key: '1', title: 'Tab 1', content: 'Content of Tab Pane 1' },
 2: { key: '2', title: 'Tab 2', content: 'Content of Tab Pane 2' },
 3: { key: '3', title: 'Tab 3', content: 'Content of Tab Pane 3' },
 }

The main logic lies here in this line which closes the tab.

setOpeningPaneKeys(openingPaneKeys.filter((openingPaneKey) => 
openingPaneKey !== paneKey))

What changes to be done for closing all tabs?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!