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

216
Views
Hacer el fondo más oscuro cuando la barra lateral está abierta en React + Typescript

Estoy tratando de personalizar una barra lateral usando react-pro-sidebar con React + Typescript. La barra lateral se ve bien, pero no puedo oscurecer la otra parte de la pantalla cuando se abre la barra lateral.

Además, me gustaría hacer que el botón que abre/cierra la barra lateral sea un botón separado. ¿Es posible en este caso?

Aquí hay un entorno limitado de trabajo de mi código hasta ahora: https://codesandbox.io/s/sleepy-lichterman-qqpp5?file=/src/App.tsx

Y el mismo código puesto aquí:

 import * as React from "react"; import { useEffect, useState } from "react"; import { ProSidebar, Menu, MenuItem, SubMenu } from "react-pro-sidebar"; import "react-pro-sidebar/dist/css/styles.css"; export interface SidebarProps { onChange?: (event: React.MouseEvent, isChecked?: boolean) => void; isCheckedInitial: boolean; } export function Sidebar({ onChange, isCheckedInitial, ...rest }: SidebarProps) { const [isChecked, setCheckedState] = useState(isCheckedInitial); useEffect(() => { setCheckedState(isCheckedInitial); }, [isCheckedInitial]); const handleChange = (event: React.MouseEvent) => { setCheckedState(!isChecked); onChange && onChange(event, isChecked); }; return ( <ProSidebar collapsed={isChecked}> <Menu iconShape="square"> <MenuItem onClick={handleChange}>click </MenuItem> <SubMenu title="Top 1"> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> </SubMenu> <SubMenu title="Top 2"> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> </SubMenu> <SubMenu title="Top 3"> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> <MenuItem>Sub menu</MenuItem> </SubMenu> </Menu> </ProSidebar> ); } export default Sidebar;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Podrías usar un div de posición fixed para eso. Edité tu ejemplo aquí: https://codesandbox.io/s/kind-babycat-cg872

Agregué un button y un div superpuesto a la barra lateral:

 <button onClick={handleChange}>click me</button> // <ProSidebar ... <div className={`overlay ${!isChecked ? 'visible' : ''}`} onClick={handleChange} />

y agregué algo de css:

 button { position: relative; z-index: 1; } .overlay { position: fixed; top: 0; left: 0; background-color: rgba(0, 0, 0, 0.5); opacity: 0; } .overlay.visible { right: 0; bottom: 0; opacity: 1; transition: opacity 0.4s; }
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!