chore(Minimap): add custom aria label for SF and RF

This commit is contained in:
Abbey Yacoe
2025-05-22 12:16:37 +02:00
parent 48c5467851
commit 3c421d5f02
5 changed files with 20 additions and 6 deletions
@@ -36,11 +36,11 @@ const selector = (s: ReactFlowState) => {
translateExtent: s.translateExtent,
flowWidth: s.width,
flowHeight: s.height,
labelConfig: s.labelConfig,
};
};
const ARIA_LABEL_KEY = 'react-flow__minimap-desc';
function MiniMapComponent<NodeType extends Node = Node>({
style,
className,
@@ -63,14 +63,17 @@ function MiniMapComponent<NodeType extends Node = Node>({
onNodeClick,
pannable = false,
zoomable = false,
ariaLabel = 'React Flow mini map',
ariaLabel,
inversePan,
zoomStep = 10,
offsetScale = 5,
}: MiniMapProps<NodeType>) {
const store = useStoreApi<NodeType>();
const svg = useRef<SVGSVGElement>(null);
const { boundingRect, viewBB, rfId, panZoom, translateExtent, flowWidth, flowHeight } = useStore(selector, shallow);
const { boundingRect, viewBB, rfId, panZoom, translateExtent, flowWidth, flowHeight, labelConfig } = useStore(
selector,
shallow
);
const elementWidth = (style?.width as number) ?? defaultWidth;
const elementHeight = (style?.height as number) ?? defaultHeight;
const scaledWidth = boundingRect.width / elementWidth;
@@ -130,6 +133,8 @@ function MiniMapComponent<NodeType extends Node = Node>({
}, [])
: undefined;
const effectiveAriaLabel = ariaLabel ?? labelConfig['minimap.ariaLabel'];
return (
<Panel
position={position}
@@ -159,7 +164,8 @@ function MiniMapComponent<NodeType extends Node = Node>({
ref={svg}
onClick={onSvgClick}
>
{ariaLabel && <title id={labelledBy}>{ariaLabel}</title>}
{effectiveAriaLabel && <title id={labelledBy}>{effectiveAriaLabel}</title>}
<MiniMapNodes<NodeType>
onClick={onSvgNodeClick}
nodeColor={nodeColor}