()
| 6 | * modals hide body overflow and the scrollbar disappears. |
| 7 | */ |
| 8 | export function useScrollbarWidth(): void { |
| 9 | useEffect(() => { |
| 10 | const update = () => { |
| 11 | const width = window.innerWidth - document.documentElement.clientWidth; |
| 12 | document.documentElement.style.setProperty( |
| 13 | '--scrollbar-width', |
| 14 | `${width}px`, |
| 15 | ); |
| 16 | }; |
| 17 | |
| 18 | update(); |
| 19 | window.addEventListener('resize', update); |
| 20 | return () => window.removeEventListener('resize', update); |
| 21 | }, []); |
| 22 | } |
no test coverage detected