diff --git a/packages/react-json-tree/src/ItemRange.tsx b/packages/react-json-tree/src/ItemRange.tsx index a051a015..ac17679d 100644 --- a/packages/react-json-tree/src/ItemRange.tsx +++ b/packages/react-json-tree/src/ItemRange.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useState } from 'react'; import JSONArrow from './JSONArrow.js'; -import type { CircularCache, CommonInternalProps } from './types.js'; +import type { CircularCache, CommonInternalProps, KeyPath } from './types.js'; interface Props extends CommonInternalProps { data: unknown; @@ -10,6 +10,7 @@ interface Props extends CommonInternalProps { renderChildNodes: (props: Props, from: number, to: number) => React.ReactNode; circularCache: CircularCache; level: number; + keyPath: KeyPath; } export default function ItemRange(props: Props) { @@ -32,6 +33,7 @@ export default function ItemRange(props: Props) { expanded={false} onClick={handleClick} arrowStyle="double" + ariaLabel={`Expand Array from ${from} to ${to}`} /> {`${from} ... ${to}`} diff --git a/packages/react-json-tree/src/JSONArrow.tsx b/packages/react-json-tree/src/JSONArrow.tsx index e00fe456..e04f6c95 100644 --- a/packages/react-json-tree/src/JSONArrow.tsx +++ b/packages/react-json-tree/src/JSONArrow.tsx @@ -6,7 +6,9 @@ interface Props { arrowStyle?: 'single' | 'double'; expanded: boolean; nodeType: string; - onClick: React.MouseEventHandler; + onClick: React.MouseEventHandler; + ariaControls?: string; + ariaLabel?: string } export default function JSONArrow({ @@ -15,15 +17,17 @@ export default function JSONArrow({ expanded, nodeType, onClick, + ariaControls, + ariaLabel }: Props) { return ( -
+
+ ); } diff --git a/packages/react-json-tree/src/JSONNestedNode.tsx b/packages/react-json-tree/src/JSONNestedNode.tsx index fbc9a47b..4cd96058 100644 --- a/packages/react-json-tree/src/JSONNestedNode.tsx +++ b/packages/react-json-tree/src/JSONNestedNode.tsx @@ -4,6 +4,7 @@ import getCollectionEntries from './getCollectionEntries.js'; import JSONNode from './JSONNode.js'; import ItemRange from './ItemRange.js'; import type { CircularCache, CommonInternalProps } from './types.js'; +import getAriaPropsFromKeyPath from './getAriaPropsFromKeyPath.js'; /** * Renders nested values (eg. objects, arrays, lists, etc.) @@ -62,6 +63,7 @@ function renderChildNodes( from={entry.from} to={entry.to} renderChildNodes={renderChildNodes} + keyPath={[entry.from, ...keyPath]} />, ); } else { @@ -141,6 +143,8 @@ export default function JSONNestedNode(props: Props) { ); const stylingArgs = [keyPath, nodeType, expanded, expandable] as const; + const {ariaControls, ariaLabel} = getAriaPropsFromKeyPath(keyPath) + return hideRoot ? (
    • @@ -155,6 +159,8 @@ export default function JSONNestedNode(props: Props) { nodeType={nodeType} expanded={expanded} onClick={handleClick} + ariaControls={ariaControls} + ariaLabel={ariaLabel} /> )}