From 1d8444572f4ab96989751a98b158902b24a068d9 Mon Sep 17 00:00:00 2001 From: Roy Johnson Date: Thu, 13 Feb 2025 20:54:04 -0600 Subject: [PATCH] Add radio role and aria checked state to color checkboxes (#2331) * Add radio role and aria checked state to color checkboxes [DISCO-323] Leaving the type as checkbox retained the functionality. Adding the role takes care of the accessibility. * Add radiogroup role to fieldset * Add trash can icon to color picker * Only show trashcan when it will do something * Separate trash button; fix tests * Hide colorpicker legends; remove space instruction * No fieldset grouping color indicators and trash icon --------- Co-authored-by: staxly[bot] <35789409+staxly[bot]@users.noreply.github.com> --- .../highlights/components/ColorIndicator.tsx | 29 + .../components/ColorPicker.spec.tsx | 23 +- .../highlights/components/ColorPicker.tsx | 80 ++- .../highlights/components/EditCard.spec.tsx | 30 +- .../highlights/components/EditCard.tsx | 14 +- .../__snapshots__/ContextMenu.spec.tsx.snap | 605 +++++++++--------- .../__snapshots__/ColorPicker.spec.tsx.snap | 581 +++++++++-------- .../__snapshots__/EditCard.spec.tsx.snap | 4 +- .../components/ShowKeyboardShortcuts.tsx | 1 - .../KeyboardShortcutsPopup.spec.tsx.snap | 18 - .../ShowKeyboardShortcuts.spec.tsx.snap | 18 - src/assets/trash-347.svg | 9 + 12 files changed, 764 insertions(+), 648 deletions(-) create mode 100644 src/assets/trash-347.svg diff --git a/src/app/content/highlights/components/ColorIndicator.tsx b/src/app/content/highlights/components/ColorIndicator.tsx index a89010bc2d..fc0e06b043 100644 --- a/src/app/content/highlights/components/ColorIndicator.tsx +++ b/src/app/content/highlights/components/ColorIndicator.tsx @@ -4,6 +4,8 @@ import { Check } from 'styled-icons/fa-solid/Check'; import { isDefined } from '../../../guards'; import { highlightStyles } from '../../constants'; import { defaultFocusOutline } from '../../../theme'; +import { useIntl } from 'react-intl'; +import trashIcon from '../../../../assets/trash-347.svg'; interface StyleProps { style: typeof highlightStyles[number]; @@ -114,4 +116,31 @@ const ColorIndicator = styled(Hoc)` } `; +function TB({ + onClick, + className, +}: { + onClick: React.MouseEventHandler | undefined; + className: string; +}) { + return ( + + ); +} + +// tslint:disable-next-line:variable-name +export const TrashButton = styled(TB)` + img { + height: ${(props: Props) => indicatorSize(props) - 0.5}rem; + width: ${(props: Props) => indicatorSize(props) - 0.5}rem; + } +`; + export default ColorIndicator; diff --git a/src/app/content/highlights/components/ColorPicker.spec.tsx b/src/app/content/highlights/components/ColorPicker.spec.tsx index 1b5c1d3123..1fc9097f69 100644 --- a/src/app/content/highlights/components/ColorPicker.spec.tsx +++ b/src/app/content/highlights/components/ColorPicker.spec.tsx @@ -4,7 +4,7 @@ import { renderToDom, dispatchKeyDownEvent } from '../../../../test/reactutils'; import TestContainer from '../../../../test/TestContainer'; import { highlightStyles } from '../../constants'; import ColorPicker from './ColorPicker'; -import { HTMLElement, HTMLFieldSetElement, HTMLInputElement } from '@openstax/types/lib.dom'; +import { HTMLElement, HTMLFieldSetElement, HTMLInputElement, HTMLButtonElement } from '@openstax/types/lib.dom'; import { assertDocument } from '../../../utils'; describe('ColorPicker', () => { @@ -84,6 +84,27 @@ describe('ColorPicker', () => { expect(onChange).not.toHaveBeenCalled(); }); + it('calls remove when trashcan is clicked', () => { + const onChange = jest.fn(); + const onRemove = jest.fn(); + + const {root} = renderToDom( + + ); + + const button = root.querySelector('button') as HTMLButtonElement; + + // This should trigger the button, but does not in testing + dispatchKeyDownEvent({ + element: button as HTMLElement, + key: 'Enter', + }); + + button.click(); + expect(onRemove).toHaveBeenCalled(); + expect(onChange).not.toHaveBeenCalled(); + }); + it('operates as a radiogroup', () => { const onChange = jest.fn(); const onRemove = jest.fn(); diff --git a/src/app/content/highlights/components/ColorPicker.tsx b/src/app/content/highlights/components/ColorPicker.tsx index 415ae6f8c2..1a49f2aba7 100644 --- a/src/app/content/highlights/components/ColorPicker.tsx +++ b/src/app/content/highlights/components/ColorPicker.tsx @@ -1,11 +1,12 @@ import { HighlightColorEnum } from '@openstax/highlighter/dist/api'; import React from 'react'; import { useIntl } from 'react-intl'; +import { hiddenButAccessible } from '../../../theme'; import styled from 'styled-components/macro'; import { match, not } from '../../../fpUtils'; import { highlightStyles } from '../../constants'; import { cardPadding } from '../constants'; -import ColorIndicator from './ColorIndicator'; +import ColorIndicator, { TrashButton } from './ColorIndicator'; import { HTMLDivElement, HTMLInputElement } from '@openstax/types/lib.dom'; interface SingleSelectProps { @@ -48,7 +49,7 @@ const ColorButton = styled(({className, size, style, ...props}: ColorButtonProps component={