Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISCO-165] Fix colorpicker focus #2201

Merged
merged 26 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2893f0b
[DISCO-146] Fix colorpicker focus
RoyEJohnson Mar 21, 2024
7167fcb
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Mar 22, 2024
c155a0a
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Mar 22, 2024
68655be
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Mar 26, 2024
460a699
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 1, 2024
ad8dcfc
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 9, 2024
bf637ac
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 9, 2024
a546de2
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 10, 2024
3d9dad1
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 10, 2024
11717c5
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 11, 2024
c3b0c3e
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 11, 2024
fd51561
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 19, 2024
314b51b
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 22, 2024
c61aba9
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 23, 2024
23e6380
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] Apr 23, 2024
4885499
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 1, 2024
aab0c0b
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 2, 2024
69bb42f
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 2, 2024
bbeef09
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 2, 2024
72d0369
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 3, 2024
cf3a764
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 3, 2024
64f0c45
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 6, 2024
b0fbafe
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 6, 2024
b1322dc
Merge branch 'main' into fix-colorpicker-focus-blip
staxly[bot] May 7, 2024
dc07e43
Merge branch 'main' into fix-colorpicker-focus-blip
Malar-Natarajan Jun 3, 2024
8201c21
Merge branch 'main' into fix-colorpicker-focus-blip
Malar-Natarajan Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('ColorPicker', () => {
const onRemove = jest.fn();
const {root} = renderToDom(
<TestContainer>
<ColorPicker onChange={onChange} onRemove={onRemove} />
<ColorPicker color={highlightStyles[0].label} onChange={onChange} onRemove={onRemove} />
</TestContainer>
);
const rg = root.querySelector('[role="radiogroup"]') as HTMLDivElement;
Expand Down
22 changes: 9 additions & 13 deletions src/app/content/highlights/components/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,18 @@ const ColorPicker = ({className, ...props}: Props) => {
},
[]
);
const initialFocus = React.useCallback(
(event: React.FocusEvent) => {
if (!ref.current || event.currentTarget !== event.target) {
return;
}
const firstChecked = ref.current.querySelector<HTMLInputElement>('input[checked]');

if (firstChecked) {
firstChecked.focus();
} else {
ref.current.querySelector<HTMLInputElement>('input')?.focus();
const color = (props as SingleSelectProps).color;
const focusOnSelected = React.useCallback(
() => {
if (color && document?.activeElement === ref.current) {
ref.current?.querySelector<HTMLInputElement>(`input[name="${color}"]`)?.focus();
}
},
[]
[color]
);

React.useEffect(focusOnSelected, [focusOnSelected]);
Dantemss marked this conversation as resolved.
Show resolved Hide resolved

return (
<div
className={className}
Expand All @@ -128,7 +124,7 @@ const ColorPicker = ({className, ...props}: Props) => {
aria-label='colors'
ref={ref}
onKeyDown={handleKeyNavigation}
onFocus={initialFocus}
onFocus={focusOnSelected}
>
{highlightStyles.map((style) => <ColorButton key={style.label}
name={style.label}
Expand Down
Loading