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

Fix/dag table a11y issues #336

Merged
merged 2 commits into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion admin/src/components/atoms/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, IconButton } from '@mui/material';
import React, { ReactElement } from 'react';

interface ActionButtonProps {
children: string;
children: React.ReactNode;
label: boolean;
icon: ReactElement;
disabled: boolean;
Expand Down
16 changes: 16 additions & 0 deletions admin/src/components/atoms/VisuallyHidden.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import styled from '@emotion/styled';

/** A component which hides its children. The children will still be available for screen readers.
* @see {@link https://www.a11yproject.com/posts/how-to-hide-content/} for further information.
*/
const VisuallyHidden = styled.span`
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
`;

export default VisuallyHidden;
58 changes: 41 additions & 17 deletions admin/src/components/molecules/DAGActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import ActionButton from '../atoms/ActionButton';
import { useNavigate } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faPlay, faStop, faReply } from '@fortawesome/free-solid-svg-icons';
import VisuallyHidden from '../atoms/VisuallyHidden';

type LabelProps = {
show: boolean;
children: React.ReactNode;
};

type Props = {
status?: Status;
Expand All @@ -14,6 +20,11 @@ type Props = {
refresh?: () => void;
};

function Label({ show, children }: LabelProps): JSX.Element {
if (show) return <>{children}</>;
return <VisuallyHidden>{children}</VisuallyHidden>;
}

function DAGActions({
status,
name,
Expand All @@ -33,12 +44,16 @@ function DAGActions({
}
) => {
const form = new FormData();
if (params.action == "start") {
let parameters = window.prompt('Enter parameters (for default parameters, leave blank and click OK).', '');
if (parameters === null) {//hint cancel
return
if (params.action == 'start') {
const parameters = window.prompt(
'Enter parameters (for default parameters, leave blank and click OK).',
''
);
if (parameters === null) {
//hint cancel
return;
}
form.set("params", parameters)
form.set('params', parameters);
} else {
if (!confirm(warn)) {
return;
Expand Down Expand Up @@ -81,9 +96,12 @@ function DAGActions({
<ActionButton
label={label}
icon={
<span className="icon">
<FontAwesomeIcon icon={faPlay} />
</span>
<>
<Label show={label}>Start</Label>
<span className="icon">
<FontAwesomeIcon icon={faPlay} />
</span>
</>
}
disabled={!buttonState['start']}
onClick={() =>
Expand All @@ -93,14 +111,17 @@ function DAGActions({
})
}
>
{label ? 'Start' : ''}
{label && 'Start'}
</ActionButton>
<ActionButton
label={label}
icon={
<span className="icon">
<FontAwesomeIcon icon={faStop} />
</span>
<>
<Label show={label}>Stop</Label>
<span className="icon">
<FontAwesomeIcon icon={faStop} />
</span>
</>
}
disabled={!buttonState['stop']}
onClick={() =>
Expand All @@ -110,14 +131,17 @@ function DAGActions({
})
}
>
{label ? 'Stop' : ''}
{label && 'Stop'}
</ActionButton>
<ActionButton
label={label}
icon={
<span className="icon">
<FontAwesomeIcon icon={faReply} />
</span>
<>
<Label show={label}>Retry</Label>
<span className="icon">
<FontAwesomeIcon icon={faReply} />
</span>
</>
}
disabled={!buttonState['retry']}
onClick={() =>
Expand All @@ -131,7 +155,7 @@ function DAGActions({
)
}
>
{label ? 'Retry' : ''}
{label && 'Retry'}
</ActionButton>
</Stack>
);
Expand Down
14 changes: 12 additions & 2 deletions admin/src/components/molecules/DAGTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import LiveSwitch from './LiveSwitch';
import moment from 'moment';
import 'moment-duration-format';
import Ticker from '../atoms/Ticker';
import VisuallyHidden from '../atoms/VisuallyHidden';

type Props = {
DAGs: DAGItem[];
Expand Down Expand Up @@ -80,9 +81,15 @@ const defaultColumns = [
}}
>
{table.getIsAllRowsExpanded() ? (
<KeyboardArrowUp />
<>
<VisuallyHidden>Compress rows</VisuallyHidden>
<KeyboardArrowUp />
</>
) : (
<KeyboardArrowDown />
<>
<VisuallyHidden>Expand rows</VisuallyHidden>
<KeyboardArrowDown />
</>
)}
</IconButton>
);
Expand Down Expand Up @@ -347,6 +354,9 @@ const defaultColumns = [
<LiveSwitch
DAG={data.DAGStatus}
refresh={props.table.options.meta?.refreshFn}
inputProps={{
'aria-label': `Toggle ${data.Name}`,
}}
/>
);
},
Expand Down
8 changes: 5 additions & 3 deletions admin/src/components/molecules/LiveSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import React from 'react';
import { DAGStatus } from '../../models';

type Props = {
inputProps?: React.HTMLProps<HTMLInputElement>;
DAG: DAGStatus;
refresh?: () => void;
};

function LiveSwitch({ DAG, refresh }: Props) {
function LiveSwitch({ DAG, refresh, inputProps }: Props) {
const [checked, setChecked] = React.useState(!DAG.Suspended);

const onSubmit = React.useCallback(
async (params: { name: string; action: string; value: string }) => {
const form = new FormData();
Expand Down Expand Up @@ -42,6 +42,8 @@ function LiveSwitch({ DAG, refresh }: Props) {
value: enabled ? 'false' : 'true',
});
}, [DAG, checked]);
return <Switch checked={checked} onChange={onChange} />;
return (
<Switch checked={checked} onChange={onChange} inputProps={inputProps} />
);
}
export default LiveSwitch;