Skip to content

Accessibility improvements on the New Workspace modal #15809

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

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 8 additions & 4 deletions components/dashboard/src/components/DropDown2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const DropDown2: FunctionComponent<DropDown2Props> = (props) => {
setShowDropDown(false);
e.preventDefault();
}
if (e.key === "Enter") {
if (e.key === "Enter" || e.key === "Space") {
if (showDropDown && selectedElementTemp && filteredOptions.some((e) => e.id === selectedElementTemp)) {
e.preventDefault();
props.onSelectionChange(selectedElementTemp);
Expand Down Expand Up @@ -158,12 +158,14 @@ export const DropDown2: FunctionComponent<DropDown2Props> = (props) => {
/>
</div>
)}
<ul>
<ul role="listbox" aria-activedescendant={selectedElementTemp} tabIndex={0}>
{filteredOptions.length > 0 ? (
filteredOptions.map((element) => {
let selectionClasses = `dark:bg-gray-800 cursor-pointer`;
if (element.id === selectedElementTemp) {
selectionClasses = `bg-gray-200 dark:bg-gray-700 cursor-pointer focus:outline-none focus:ring-0`;
const active = element.id === selectedElementTemp;

if (active) {
selectionClasses = `bg-gray-200 dark:bg-gray-700 cursor-pointer focus:outline-none focus:ring-0`;
}
if (!element.isSelectable) {
selectionClasses = ``;
Expand All @@ -173,6 +175,8 @@ export const DropDown2: FunctionComponent<DropDown2Props> = (props) => {
key={element.id}
id={element.id}
tabIndex={0}
role="option"
aria-selected={active}
className={"h-16 rounded-lg flex items-center px-2 " + selectionClasses}
onMouseDown={() => {
if (element.isSelectable) {
Expand Down
26 changes: 21 additions & 5 deletions components/dashboard/src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export default function Modal(props: {
}

return (
<div className="fixed top-0 left-0 bg-black bg-opacity-70 z-50 w-screen h-screen">
<div
className="fixed top-0 left-0 bg-black bg-opacity-70 z-50 w-screen h-screen"
aria-labelledby="modal-title"
role="alertdialog"
>
<div className="w-screen h-screen align-middle" style={{ display: "table-cell" }}>
<div
className={cn(
Expand All @@ -82,15 +86,23 @@ export default function Modal(props: {
)}
>
{props.closeable !== false && (
<div
className="absolute right-7 top-6 cursor-pointer text-gray-800 dark:text-gray-100 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-md p-2"
<button
className="absolute right-7 top-6 cursor-pointer text-gray-800 bg-transparent dark:text-gray-100 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-md p-2"
aria-label="Close this modal"
onKeyDown={(e) => {
// Prevent the modal from submitting when attempting to close it
if (e.key === "Enter" || e.key === "Space") {
e.preventDefault();
closeModal("x");
}
}}
onClick={() => closeModal("x")}
>
<svg version="1.1" width="14px" height="14px" viewBox="0 0 100 100">
<line x1="0" y1="0" x2="100" y2="100" stroke="currentColor" strokeWidth="10px" />
<line x1="0" y1="100" x2="100" y2="0" stroke="currentColor" strokeWidth="10px" />
</svg>
</div>
</button>
)}
{props.title ? (
<>
Expand All @@ -112,7 +124,11 @@ type ModalHeaderProps = {
};

export const ModalHeader = ({ children }: ModalHeaderProps) => {
return <h3 className="pb-2">{children}</h3>;
return (
<h3 className="pb-2" id="modal-title">
{children}
</h3>
);
};

type ModalBodyProps = {
Expand Down