From 8516dd89c83c0ec52ff9618e66edb2d98a887c51 Mon Sep 17 00:00:00 2001 From: Tyler Jones Date: Fri, 13 Sep 2024 13:56:36 -0400 Subject: [PATCH 1/6] Add test case --- .../react/src/TooltipV2/__tests__/Tooltip.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx index df52b73dcbd..adee1509385 100644 --- a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx +++ b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx @@ -109,4 +109,17 @@ describe('Tooltip', () => { const triggerEL = getByRole('button') expect(triggerEL.getAttribute('aria-describedby')).toContain('custom-tooltip-id') }) + it('should not throw an error when the trigger element is a button', () => { + const {getByRole} = HTMLRender( +
+ Legend + + + +
, + ) + + const triggerEL = getByRole('button') + expect(triggerEL).toBeInTheDocument() + }) }) From 9bda20b1b66588e41a6444070b34fcfd9711a679 Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Mon, 16 Sep 2024 11:00:25 +1000 Subject: [PATCH 2/6] Update the disabled selector and add another test --- packages/react/src/TooltipV2/Tooltip.tsx | 2 +- .../react/src/TooltipV2/__tests__/Tooltip.test.tsx | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/react/src/TooltipV2/Tooltip.tsx b/packages/react/src/TooltipV2/Tooltip.tsx index b4756ff12d0..ab5c5fe6648 100644 --- a/packages/react/src/TooltipV2/Tooltip.tsx +++ b/packages/react/src/TooltipV2/Tooltip.tsx @@ -171,7 +171,7 @@ const positionToDirection: Record = { // The list is from GitHub's custom-axe-rules https://github.com/github/github/blob/master/app/assets/modules/github/axe-custom-rules.ts#L3 const interactiveElements = [ 'a[href]', - 'button:not(:disabled)', + 'button:not([disabled])', 'summary', 'select', 'input:not([type=hidden])', diff --git a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx index adee1509385..aac3797b60d 100644 --- a/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx +++ b/packages/react/src/TooltipV2/__tests__/Tooltip.test.tsx @@ -109,6 +109,20 @@ describe('Tooltip', () => { const triggerEL = getByRole('button') expect(triggerEL.getAttribute('aria-describedby')).toContain('custom-tooltip-id') }) + it('should throw an error if the trigger element is disabled', () => { + const spy = jest.spyOn(console, 'error').mockImplementation() + expect(() => { + HTMLRender( + + + , + ) + }).toThrow( + 'The `Tooltip` component expects a single React element that contains interactive content. Consider using a `