Skip to content

Commit a3bd9d4

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(ui): prevent focus in closed details panels
1 parent 464c9e0 commit a3bd9d4

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

‎packages/emcn/src/components/details-panel/details-panel.test.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ it('forwards resize events and retains content and refs while closed', () => {
2727
try {
2828
act(() => root.render(render(true)))
2929
const panel = ref.current!
30+
expect(panel.hasAttribute('inert')).toBe(false)
3031
const input = panel.querySelector('input')!
3132
const handle = container.querySelector('[role="separator"]')!
3233
expect(handle.getAttribute('aria-label')).toBe('Resize details')
@@ -36,11 +37,13 @@ it('forwards resize events and retains content and refs while closed', () => {
3637
expect(resize.mock.calls[0][0].clientX).toBe(240)
3738

3839
act(() => root.render(render(false)))
40+
expect(panel.hasAttribute('inert')).toBe(true)
3941
expect(ref.current).toBe(panel)
4042
expect(panel.querySelector('input')).toBe(input)
4143
expect(input.value).toBe('Retained query')
4244
expect(container.querySelector('[role="separator"]')).toBeNull()
4345
act(() => root.render(render(true)))
46+
expect(panel.hasAttribute('inert')).toBe(false)
4447
expect(panel.querySelector('input')).toBe(input)
4548
expect(container.querySelector('[role="separator"]')).not.toBeNull()
4649
} finally {

‎packages/emcn/src/components/details-panel/details-panel.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type CSSProperties, forwardRef, type HTMLAttributes, type MouseEventHan
22
import { cn } from '../../lib/cn'
33

44
export interface DetailsPanelProps extends HTMLAttributes<HTMLDivElement> {
5-
/** Slide the panel into view without unmounting its content. */
5+
/** Slide the panel into view; closed content stays mounted but inert. */
66
open: boolean
77
/** Controlled width, including responsive CSS expressions such as clamp(). */
88
width: NonNullable<CSSProperties['width']>
@@ -42,6 +42,7 @@ export const DetailsPanel = forwardRef<HTMLDivElement, DetailsPanelProps>(
4242
<div
4343
{...props}
4444
ref={ref}
45+
inert={!open || props.inert}
4546
className={cn(
4647
'absolute top-0 right-0 bottom-0 z-[var(--z-dropdown)] overflow-hidden border-l bg-[var(--bg)] shadow-md transition-transform duration-200 ease-out',
4748
open ? 'translate-x-0' : 'translate-x-full',

0 commit comments

Comments
 (0)