Skip to content

Commit

Permalink
fix: a11y use of Sharing and Actions menus
Browse files Browse the repository at this point in the history
  • Loading branch information
deodorhunter committed Feb 1, 2024
1 parent bdb53b9 commit c70ee34
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 21 deletions.
7 changes: 7 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,18 @@
- ...
-->

## Versione X.X.X (dd/mm/yyyy)

### Fix

- [ Accessibilità ] Risolto un problema relativo alla navigazione da tastiera e di gestione del focus nei menu a tendina "Condividi" e "Azioni" nelle testate delle viste dei Content Type che le implementano.

## Versione 11.3.3 (30/01/2024)

### Migliorie

- Migliorato il focus sulle immagini in edit del blocco Immagine quando queste sono allineate a sinistra o a destra.

### Fix

- Sistemato il layout del blocco elenco per i Bandi
Expand Down
73 changes: 53 additions & 20 deletions src/components/ItaliaTheme/View/Commons/Actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
LinkListItem,
Button,
} from 'design-react-kit';

import { toPublicURL } from '@plone/volto/helpers';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';

Expand Down Expand Up @@ -42,7 +41,7 @@ const messages = defineMessages({
const Actions = (props) => {
const intl = useIntl();
const publicUrl = toPublicURL(props.url);
let socials = [
const socials = [
{
id: 'print',
attributes: null,
Expand All @@ -58,8 +57,25 @@ const Actions = (props) => {
icon: 'it-mail',
},
];
const handlePrint = (e) => {
e.preventDefault();
return window.print();
};
const handleKeyDown = (e) => {
if (e.key === 'Enter' || e.code === 'Space') {
const childElement = e.target.firstChild;
if (childElement.tagName === 'BUTTON' || childElement.tagName === 'A') {
// La libreria del dropdown ha dei problemi nel suo focus manager interno.
// Enter e spazio chiudono il menu, quindi fermiamo il bubbling (per chiudere si usa esc,
// come correttamente dichiarato dallo screen reader), poi simuliamo il click
e.stopPropagation();
childElement.click();
}
}
};

return (
<UncontrolledDropdown className="d-inline page-actions">
<UncontrolledDropdown className="d-inline page-actions" id="page-actions">
<DropdownToggle
className={`btn btn-dropdown ps-0`}
color=""
Expand All @@ -81,6 +97,14 @@ const Actions = (props) => {
<DropdownMenu>
<LinkList>
{socials.map((item, i) => {
const commonButtonProps = {
icon: false,
title: item.title,
alt: item.title,
'aria-label': item.title,
id: item.id,
};

const icon = (
<>
<Icon
Expand All @@ -95,23 +119,32 @@ const Actions = (props) => {
<span>{item.title}</span>
</>
);
return item.id === 'print' ? (
<li key={item.id}>
<Button
color="link"
icon={false}
tag="button"
onClick={(e) => {
e.preventDefault();
return window.print();
}}
>
{icon}
</Button>
</li>
) : (
<LinkListItem href={item.url} key={item.id}>
{icon}

let buttonProps = { ...commonButtonProps };
if (item.id === 'print')
buttonProps = {
...commonButtonProps,
tag: 'button',
onClick: handlePrint,
color: 'link',
};
else if (item.id === 'mailto')
buttonProps = {
...commonButtonProps,
href: item.url,
};
return (
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menu_role#:~:text=within%20the%20menu-,tabindex,-attribute
<LinkListItem
key={item.id}
role="menuitem"
tabIndex={-1}
onKeyDown={handleKeyDown}
>
{item.id === 'print' && (
<Button {...buttonProps}>{icon}</Button>
)}
{item.id === 'mailto' && <a {...buttonProps}>{icon}</a>}
</LinkListItem>
);
})}
Expand Down
8 changes: 7 additions & 1 deletion src/components/ItaliaTheme/View/Commons/Sharing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ const Sharing = ({ url, title }) => {
<DropdownMenu>
<LinkList>
{socials.map((item, i) => (
<LinkListItem href={item.url} key={item.id} target="_target">
<LinkListItem
href={item.url}
key={item.id}
target="_target"
role="menuitem"
tabIndex={-1}
>
<Icon
className={undefined}
color=""
Expand Down
2 changes: 2 additions & 0 deletions src/theme/ItaliaTheme/Components/_sharing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
ul {
li {
a.list-item,
a.list-item a,
button.btn-link {
display: flex;
align-items: center;
font-size: var(--bs-dropdown-font-size);

.icon {
width: 28px;
Expand Down

0 comments on commit c70ee34

Please sign in to comment.