fix(ui): keep drag handles free of pointer focus outlines

This commit is contained in:
Codex
2026-11-17 01:55:47 +03:00
parent 8539a211ed
commit 533723883d
13 changed files with 72 additions and 19 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@nodedc/ui-react",
"version": "0.7.3",
"version": "0.7.4",
"type": "module",
"files": [
"dist"
@@ -21,7 +21,7 @@
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@nodedc/ui-core": "0.7.1",
"@nodedc/ui-core": "0.7.2",
"lucide-react": "^0.468.0"
},
"peerDependencies": {
+2 -1
View File
@@ -1,3 +1,4 @@
import {dragHandleFocus} from './dragHandleFocus.js';
import {useEffect,useLayoutEffect,useRef,useState,type KeyboardEvent,type PointerEvent,type ReactNode} from 'react';
import {constrainDockTree,dockIds,dockMinimum,dockRects,dockEditorTool,editorDockTarget,mergeEditorDockRatios,pruneDockTree,resizeDockSplit,type DockMinimum,type DockMove,type DockRect,type DockTree,type EditorDockState} from '@nodedc/ui-core';
import {IconButton} from './Button.js';
@@ -105,7 +106,7 @@ export function EditorDockLayout({value,onChange,primary,primaryId='viewport',pr
return <div key={tool.id} className={cn('nodedc-editor-dock__tool nodedc-glass-material nodedc-ui-root',tool.className)} data-editor-tool={tool.id} data-floating={free||undefined} data-glass-context={free?'scene':undefined} data-dock-corners={free?undefined:editorDockCorners(rect,area)} data-active={order.at(-1)===tool.id||undefined}
role="region" aria-label={tool.label} hidden={!enabled||!tool.open} style={{...rect,zIndex:moving?40:free?10+Math.max(0,order.indexOf(tool.id)):1}}
onPointerDownCapture={()=>activate(tool.id)} onFocusCapture={()=>activate(tool.id)}>
<header className="nodedc-window__head" tabIndex={0} aria-label={`Переместить · ${tool.label}`} aria-roledescription="Перемещаемая панель" onPointerDown={e=>begin(tool.id,e)} onKeyDown={e=>key(tool.id,e)}>
<header {...dragHandleFocus} className="nodedc-window__head" tabIndex={0} aria-label={`Переместить · ${tool.label}`} aria-roledescription="Перемещаемая панель" onPointerDown={e=>begin(tool.id,e)} onKeyDown={e=>key(tool.id,e)}>
<div className="nodedc-window__titles"><h2 className="nodedc-window__title">{tool.title}</h2>{tool.subtitle&&<p className="nodedc-window__subtitle">{tool.subtitle}</p>}</div>
<div className="nodedc-window__actions">{tool.actions}<IconButton label={`Закрыть · ${tool.label}`} onClick={tool.onClose}><Icon name="close"/></IconButton></div>
</header>
+2
View File
@@ -1,3 +1,4 @@
import {dragHandleFocus} from './dragHandleFocus.js';
import {
useCallback,
useEffect,
@@ -262,6 +263,7 @@ export function Window({
{...props}
>
<header
{...dragHandleFocus}
className="nodedc-window__head"
tabIndex={freeGeometry ? 0 : undefined}
aria-label={freeGeometry ? "Перемещение окна: стрелки; изменение размера: Shift и стрелки" : undefined}
@@ -1,3 +1,4 @@
import {dragHandleFocus} from './dragHandleFocus.js';
import {
useEffect,
useId,
@@ -397,6 +398,7 @@ export function WorkspaceWindow({
}}
>
<header
{...dragHandleFocus}
ref={headRef}
className="nodedc-workspace-window__head"
tabIndex={maximized ? -1 : 0}
+15
View File
@@ -0,0 +1,15 @@
import type {FocusEvent, KeyboardEvent, PointerEvent} from 'react';
/** A pointer grab must not inherit the previous input's keyboard focus ring. */
export const dragHandleFocus = {
onPointerDownCapture(event: PointerEvent<HTMLElement>) {
if (event.button !== 0 || (event.target as HTMLElement).closest('button,input,select,textarea,a,[role=slider]')) return;
event.currentTarget.dataset.pointerFocus = 'true';
},
onKeyDownCapture(event: KeyboardEvent<HTMLElement>) {
if (event.target === event.currentTarget) delete event.currentTarget.dataset.pointerFocus;
},
onBlur(event: FocusEvent<HTMLElement>) {
if (event.target === event.currentTarget) delete event.currentTarget.dataset.pointerFocus;
},
};