Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

341
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda