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

121
Views
La barra de navegación del lado del menú de iones se cierra si hago clic en el elemento de iones de cualquier lista de iones

aquí está mi código

Menú.tsx

 const Menu = () => { const showCat = () => { let res = Array(5) .fill(0) .map((_, i) => ( <IonItem key={i}> <IonLabel>Cat{i}</IonLabel> </IonItem> )); return <IonList>{res}</IonList>; }; return ( <> <IonHeader> <IonToolbar> <IonTitle>Meme11</IonTitle> </IonToolbar> </IonHeader> <IonContent> <IonList> <IonMenuToggle auto-hide="false"> <IonItem button routerLink={"/home"} routerDirection="none"> <IonLabel>Home</IonLabel> </IonItem> <IonItem button routerLink={"/about"} routerDirection="none"> <IonLabel>About</IonLabel> </IonItem> <IonItem onClick={() => { showCat(); }} > <IonLabel>Categories</IonLabel> </IonItem> </IonMenuToggle> </IonList> </IonContent> </> ); };

Aplicación.tsx

 const App: React.FC = () => ( <IonApp> <IonSplitPane contentId="menu"> <IonMenu class="custom" contentId="menu"> <Menu /> </IonMenu> <IonReactRouter> <IonRouterOutlet id="menu"> <Route exact path="/home"> <Home /> </Route> <Route exact path="/"> <Redirect to="/home" /> </Route> <Route exact path="/about"> <About /> </Route> </IonRouterOutlet> </IonReactRouter> </IonSplitPane> </IonApp> );

En el código anterior, si hago clic en cualquier elemento de la lista de iones, la navegación lateral se cierra (alterna). Y no quiero que se cierre solo si hago clic fuera de sidenav o en el botón ionmenu, debería cerrarse. Si hago clic en las 'categorías' de ionitem, entonces se debería llamar a la función showCat y debería devolver la lista de iones anidada.

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intentaría detener la propagación.

 <IonItem onClick={(e) => { e.stopPropagation(); showCat(); }} >

Vea más aquí: https://reactjs.org/docs/handling-events.html

ACTUALIZAR:

Para que la barra lateral permanezca, simplemente elimine el botón de menú de iones, así:

 <IonContent> <IonList> <IonItem button routerLink={"/home"} routerDirection="none"> <IonLabel>Home</IonLabel> </IonItem> <IonItem button routerLink={"/about"} routerDirection="none"> <IonLabel>About</IonLabel> </IonItem> <IonItem onClick={(e) => { e.stopPropagation(); showCat(); }} > <IonLabel>Categories</IonLabel> </IonItem> </IonList> </IonContent>
about 4 years ago · Juan Pablo Isaza Report
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!