From 619c6559d2cc28b5ffecd3509c0e3bb95530c5ed Mon Sep 17 00:00:00 2001 From: Carl Smith <5456533+CarlosNZ@users.noreply.github.com> Date: Tue, 16 Jun 2026 09:35:25 +1200 Subject: [PATCH 1/5] Change div to button --- .changeset/button-controls-accessibility.md | 7 ++ README.md | 6 +- migration-guide.md | 16 ++++ src/ButtonPanels.tsx | 81 +++++++++++++++++---- src/CollectionNode.tsx | 2 + src/JsonEditor.tsx | 2 +- src/ValueNodeWrapper.tsx | 2 + src/localisation.ts | 2 + src/style.css | 19 +++++ src/types.ts | 2 +- test/JsonEditor.test.tsx | 61 +++++++++++++++- test/customNode.test.tsx | 28 +++---- 12 files changed, 191 insertions(+), 37 deletions(-) create mode 100644 .changeset/button-controls-accessibility.md diff --git a/.changeset/button-controls-accessibility.md b/.changeset/button-controls-accessibility.md new file mode 100644 index 00000000..38dc023b --- /dev/null +++ b/.changeset/button-controls-accessibility.md @@ -0,0 +1,7 @@ +--- +'json-edit-react': major +--- + +The clickable icon controls — the ✓ / ✗ confirm/cancel pair and the edit/copy/delete/add icons — are now real ` )} {startEdit && ( -
-
+ )} {handleDelete && ( -
-
+ )} {handleAdd && ( -
{ // Objects open a key-entry session; arrays add a default value // immediately (no key to fill — a one-shot, as before). if (type === 'object') openAdd() else handleAdd('') }} + aria-label={translate('TOOLTIP_ADD', nodeData)} title={showIconTooltips ? translate('TOOLTIP_ADD', nodeData) : ''} > -
+ )} {customButtons?.map(({ Element, onClick }, i) => ( + // Custom buttons stay
s: the inner `Element` is consumer-owned and + // may itself be interactive, so wrapping it in a
+ )} -
+
+ ) } diff --git a/src/CollectionNode.tsx b/src/CollectionNode.tsx index efcaf957..6474ae9b 100644 --- a/src/CollectionNode.tsx +++ b/src/CollectionNode.tsx @@ -446,6 +446,8 @@ const CollectionNodeBase: React.FC = (props) => { onOk={handleEdit} onCancel={handleCancel} nodeData={nodeData} + translate={translate} + showIconTooltips={showIconTooltips} editConfirmRef={editConfirmRef} /> diff --git a/src/JsonEditor.tsx b/src/JsonEditor.tsx index be534e9f..1a360fb7 100644 --- a/src/JsonEditor.tsx +++ b/src/JsonEditor.tsx @@ -539,7 +539,7 @@ const Editor: React.FC< } }, [customNodeDefinitions, jsonParse]) - const editConfirmRef = useRef(null) + const editConfirmRef = useRef(null) const { setCollapseState } = useCollapse() // Common "sort" method for ordering nodes, based on the `sortKeys` prop diff --git a/src/ValueNodeWrapper.tsx b/src/ValueNodeWrapper.tsx index aeb5384e..d85008f7 100644 --- a/src/ValueNodeWrapper.tsx +++ b/src/ValueNodeWrapper.tsx @@ -517,6 +517,8 @@ const ValueNodeWrapperBase: React.FC = (props) => { onOk={handleEdit} onCancel={handleCancel} nodeData={nodeData} + translate={translate} + showIconTooltips={showIconTooltips} editConfirmRef={editConfirmRef} /> ) : ( diff --git a/src/localisation.ts b/src/localisation.ts index 5b3bca2d..0ac1bdff 100644 --- a/src/localisation.ts +++ b/src/localisation.ts @@ -22,6 +22,8 @@ const localisedStrings = { TOOLTIP_EDIT: 'Edit', TOOLTIP_DELETE: 'Delete', TOOLTIP_ADD: 'Add', + TOOLTIP_OK: 'OK', + TOOLTIP_CANCEL: 'Cancel', } export type LocalisedStrings = typeof localisedStrings diff --git a/src/style.css b/src/style.css index 464cc75a..1f2f9c75 100644 --- a/src/style.css +++ b/src/style.css @@ -334,6 +334,25 @@ select:focus + .focus { height: 1em; } +/* The icon controls are real