Skip to content

Commit

Permalink
Make highlight Actions menu items (Edit and Delete) buttons
Browse files Browse the repository at this point in the history
[DISCO-307]
For clarity, changed `ol` to `menu`
Also simplified return value of DropdownItem.
  • Loading branch information
RoyEJohnson committed Aug 27, 2024
1 parent 4ef6866 commit d5b5e50
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 54 deletions.
7 changes: 4 additions & 3 deletions src/app/components/Dropdown.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ describe('Dropdown', () => {
</TestContainer>);

renderer.act(() => {
const [button1, button2] = component.root.findAllByType('a');
button1.props.onClick(mockEv);
button2.props.onClick(mockEv);
const items = component.root.findAll((i) => i.props.onClick && i.type === 'button');

items.forEach((i) => i.props.onClick(mockEv));
expect(items.length).toBe(2);
});

expect(mockEv.preventDefault).toHaveBeenCalledTimes(2);
Expand Down
32 changes: 17 additions & 15 deletions src/app/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,14 @@ function TrappingDropdownList(props: object) {
useTrapTabNavigation(ref);

return (
<ol ref={ref} {...props} />
<menu ref={ref} {...props} />
);
}


// tslint:disable-next-line:variable-name
export const DropdownList = styled(TrappingDropdownList)`
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: ${theme.color.neutral.formBackground};
Expand Down Expand Up @@ -237,22 +238,23 @@ const DropdownItemContent = ({
});
return <FormattedMessage id={message}>
{(msg) => href
? <a href={href} tabIndex={0} onClick={onClick} target={target} {...analyticsDataProps}>{prefix}{msg}</a>
/*
this should be a button but Safari and firefox don't support focusing buttons
which breaks the tab transparent dropdown
https://bugs.webkit.org/show_bug.cgi?id=22261
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
*/
// eslint-disable-next-line jsx-a11y/anchor-is-valid
: <a
? <a
role='button'
href={href}
tabIndex={0}
onClick={onClick}
target={target}
{...analyticsDataProps}
>{prefix}{msg}</a>
// Safari support tab-navigation of buttons; this operates with space or Enter
: <button
type='button'
tabIndex={0}
href=''
onClick={onClick ? flow(preventDefault, onClick) : preventDefault}
{...analyticsDataProps}
>
{prefix}{msg}
</a>
</button>
}
</FormattedMessage>;
};
Expand All @@ -261,9 +263,9 @@ const DropdownItemContent = ({
export const DropdownItem = ({ariaMessage, ...contentProps}: DropdownItemProps) => {
const intl = useIntl();

return ariaMessage
? <li aria-label={intl.formatMessage({id: ariaMessage})}><DropdownItemContent {...contentProps}/></li>
: <li><DropdownItemContent {...contentProps} /></li>;
return <li aria-label={ariaMessage ? intl.formatMessage({id: ariaMessage}) : undefined}>
<DropdownItemContent {...contentProps}/>
</li>;
};

interface CommonDropdownProps {
Expand Down
24 changes: 14 additions & 10 deletions src/app/components/__snapshots__/DotMenu.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ exports[`Dropdown matches snapshot 1`] = `
}
.c12 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -224,28 +225,29 @@ exports[`Dropdown matches snapshot 1`] = `
</svg>
</div>
</button>
<ol
<menu
className="c12"
>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Delete
</a>
</button>
</li>
<li>
<a
href="/wooo"
onClick={[Function]}
role="button"
tabIndex={0}
>
Edit
</a>
</li>
</ol>
</menu>
</div>
<button
aria-label="Actions"
Expand Down Expand Up @@ -409,6 +411,7 @@ exports[`Dropdown matches snapshot on right align 1`] = `
}
.c12 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -497,29 +500,30 @@ exports[`Dropdown matches snapshot on right align 1`] = `
</svg>
</div>
</button>
<ol
<menu
className="c12"
rightAlign={true}
>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Delete
</a>
</button>
</li>
<li>
<a
href="/wooo"
onClick={[Function]}
role="button"
tabIndex={0}
>
Edit
</a>
</li>
</ol>
</menu>
</div>
<button
aria-label="Actions"
Expand Down
24 changes: 14 additions & 10 deletions src/app/components/__snapshots__/Dropdown.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ exports[`Dropdown matches snapshot 1`] = `
}
.c6 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -155,28 +156,29 @@ exports[`Dropdown matches snapshot 1`] = `
>
show more
</button>
<ol
<menu
className="c6"
>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Delete
</a>
</button>
</li>
<li>
<a
href="/wooo"
onClick={[Function]}
role="button"
tabIndex={0}
>
Edit
</a>
</li>
</ol>
</menu>
</div>
<button
className="c4 c5"
Expand Down Expand Up @@ -400,6 +402,7 @@ exports[`Dropdown matches snapshot for tab hidden (open) 1`] = `
}
.c4 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -461,27 +464,28 @@ exports[`Dropdown matches snapshot for tab hidden (open) 1`] = `
>
show more
</button>
<ol
<menu
className="c4"
>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Delete
</a>
</button>
</li>
<li>
<a
href="/wooo"
onClick={[Function]}
role="button"
tabIndex={0}
>
Edit
</a>
</li>
</ol>
</menu>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ exports[`ContextMenu match snapshot when open 1`] = `
}
.c13 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -644,7 +645,7 @@ exports[`ContextMenu match snapshot when open 1`] = `
<div
className="c12"
>
<ol
<menu
className="c13"
>
<li>
Expand Down Expand Up @@ -967,10 +968,10 @@ exports[`ContextMenu match snapshot when open 1`] = `
<li
aria-label="Add note"
>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
<svg
aria-hidden="true"
Expand All @@ -986,15 +987,15 @@ exports[`ContextMenu match snapshot when open 1`] = `
/>
</svg>
Add note
</a>
</button>
</li>
<li
aria-label="Delete"
>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
<svg
aria-hidden="true"
Expand All @@ -1010,12 +1011,13 @@ exports[`ContextMenu match snapshot when open 1`] = `
/>
</svg>
Delete
</a>
</button>
</li>
<li>
<a
data-analytics-region="MH gotohighlight"
href="/link/to/highlight"
role="button"
tabIndex={0}
target="_blank"
>
Expand All @@ -1035,7 +1037,7 @@ exports[`ContextMenu match snapshot when open 1`] = `
Go to highlight
</a>
</li>
</ol>
</menu>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ exports[`DisplayNote matches snapshot when focused with opened dropdown 1`] = `
}
.c12 {
list-style: none;
margin: 0;
padding: 0.6rem 0;
background: #f5f5f5;
Expand Down Expand Up @@ -612,28 +613,28 @@ exports[`DisplayNote matches snapshot when focused with opened dropdown 1`] = `
</svg>
</div>
</button>
<ol
<menu
className="c11 c12"
>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Edit
</a>
</button>
</li>
<li>
<a
href=""
<button
onClick={[Function]}
tabIndex={0}
type="button"
>
Delete
</a>
</button>
</li>
</ol>
</menu>
</div>
<svg
aria-hidden="true"
Expand Down

0 comments on commit d5b5e50

Please sign in to comment.