forked from github/plane
[WEB-586] chore: spreadsheet layout keyboard accessibility (#3818)
* chore: spreadsheet layout peek overview close focus improvement * chore: dropdown toggle focus improvement * chore: label select toggle focus improvement * chore: comment card disabled state improvement
This commit is contained in:
parent
0f56945321
commit
b1520783cf
@ -86,6 +86,7 @@ export const DateDropdown: React.FC<Props> = (props) => {
|
|||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) onOpen();
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropdownOnChange = (val: Date | null) => {
|
const dropdownOnChange = (val: Date | null) => {
|
||||||
|
@ -122,6 +122,7 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) onOpen();
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropdownOnChange = (val: number | null) => {
|
const dropdownOnChange = (val: number | null) => {
|
||||||
|
@ -175,6 +175,7 @@ export const ModuleDropdown: React.FC<Props> = observer((props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropdownOnChange = (val: string & string[]) => {
|
const dropdownOnChange = (val: string & string[]) => {
|
||||||
|
@ -314,6 +314,7 @@ export const PriorityDropdown: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropdownOnChange = (val: TIssuePriorities) => {
|
const dropdownOnChange = (val: TIssuePriorities) => {
|
||||||
|
@ -104,6 +104,7 @@ export const StateDropdown: React.FC<Props> = observer((props) => {
|
|||||||
const toggleDropdown = () => {
|
const toggleDropdown = () => {
|
||||||
if (!isOpen) onOpen();
|
if (!isOpen) onOpen();
|
||||||
setIsOpen((prevIsOpen) => !prevIsOpen);
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const dropdownOnChange = (val: string) => {
|
const dropdownOnChange = (val: string) => {
|
||||||
|
@ -149,9 +149,13 @@ export const IssueCommentCard: FC<TIssueCommentCard> = (props) => {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={handleSubmit(onEnter)}
|
onClick={handleSubmit(onEnter)}
|
||||||
disabled={isSubmitting || isEmpty}
|
disabled={isSubmitting || isEmpty}
|
||||||
className="group rounded border border-green-500 bg-green-500/20 p-2 shadow-md duration-300 hover:bg-green-500"
|
className={`group rounded border border-green-500 bg-green-500/20 p-2 shadow-md duration-300 ${
|
||||||
|
isEmpty ? "bg-gray-200 cursor-not-allowed" : "hover:bg-green-500"
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
<Check className="h-3 w-3 text-green-500 duration-300 group-hover:text-white" />
|
<Check
|
||||||
|
className={`h-3 w-3 text-green-500 duration-300 ${isEmpty ? "text-black" : "group-hover:text-white"}`}
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Fragment, useState } from "react";
|
import { Fragment, useEffect, useRef, useState } from "react";
|
||||||
import { observer } from "mobx-react-lite";
|
import { observer } from "mobx-react-lite";
|
||||||
import { usePopper } from "react-popper";
|
import { usePopper } from "react-popper";
|
||||||
import { Check, ChevronDown, Search, Tags } from "lucide-react";
|
import { Check, ChevronDown, Search, Tags } from "lucide-react";
|
||||||
// hooks
|
// hooks
|
||||||
import { useApplication, useLabel } from "hooks/store";
|
import { useApplication, useLabel } from "hooks/store";
|
||||||
import { useDropdownKeyDown } from "hooks/use-dropdown-key-down";
|
import { useDropdownKeyDown } from "hooks/use-dropdown-key-down";
|
||||||
|
import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
||||||
// components
|
// components
|
||||||
import { Combobox } from "@headlessui/react";
|
import { Combobox } from "@headlessui/react";
|
||||||
import { Tooltip } from "@plane/ui";
|
import { Tooltip } from "@plane/ui";
|
||||||
@ -48,6 +49,10 @@ export const IssuePropertyLabels: React.FC<IIssuePropertyLabels> = observer((pro
|
|||||||
} = props;
|
} = props;
|
||||||
// states
|
// states
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
// refs
|
||||||
|
const dropdownRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const inputRef = useRef<HTMLInputElement | null>(null);
|
||||||
// popper-js refs
|
// popper-js refs
|
||||||
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
|
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
|
||||||
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
||||||
@ -60,18 +65,45 @@ export const IssuePropertyLabels: React.FC<IIssuePropertyLabels> = observer((pro
|
|||||||
|
|
||||||
const storeLabels = getProjectLabels(projectId);
|
const storeLabels = getProjectLabels(projectId);
|
||||||
|
|
||||||
const openDropDown = () => {
|
const onOpen = () => {
|
||||||
if (!storeLabels && workspaceSlug && projectId) {
|
if (!storeLabels && workspaceSlug && projectId)
|
||||||
setIsLoading(true);
|
|
||||||
fetchProjectLabels(workspaceSlug, projectId).then(() => setIsLoading(false));
|
fetchProjectLabels(workspaceSlug, projectId).then(() => setIsLoading(false));
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
|
if (!isOpen) return;
|
||||||
|
setIsOpen(false);
|
||||||
onClose && onClose();
|
onClose && onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyDown = useDropdownKeyDown(openDropDown, handleClose, false);
|
const toggleDropdown = () => {
|
||||||
|
if (!isOpen) onOpen();
|
||||||
|
setIsOpen((prevIsOpen) => !prevIsOpen);
|
||||||
|
if (isOpen) onClose && onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = useDropdownKeyDown(toggleDropdown, handleClose);
|
||||||
|
|
||||||
|
const handleOnClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
toggleDropdown();
|
||||||
|
};
|
||||||
|
|
||||||
|
useOutsideClickDetector(dropdownRef, handleClose);
|
||||||
|
|
||||||
|
const searchInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (query !== "" && e.key === "Escape") {
|
||||||
|
e.stopPropagation();
|
||||||
|
setQuery("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen && inputRef.current) {
|
||||||
|
inputRef.current.focus();
|
||||||
|
}
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
const { styles, attributes } = usePopper(referenceElement, popperElement, {
|
||||||
placement: placement ?? "bottom-start",
|
placement: placement ?? "bottom-start",
|
||||||
@ -176,6 +208,7 @@ export const IssuePropertyLabels: React.FC<IIssuePropertyLabels> = observer((pro
|
|||||||
return (
|
return (
|
||||||
<Combobox
|
<Combobox
|
||||||
as="div"
|
as="div"
|
||||||
|
ref={dropdownRef}
|
||||||
className={`w-auto max-w-full flex-shrink-0 text-left ${className}`}
|
className={`w-auto max-w-full flex-shrink-0 text-left ${className}`}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
@ -194,64 +227,68 @@ export const IssuePropertyLabels: React.FC<IIssuePropertyLabels> = observer((pro
|
|||||||
? "cursor-pointer"
|
? "cursor-pointer"
|
||||||
: "cursor-pointer hover:bg-custom-background-80"
|
: "cursor-pointer hover:bg-custom-background-80"
|
||||||
} ${buttonClassName}`}
|
} ${buttonClassName}`}
|
||||||
onClick={openDropDown}
|
onClick={handleOnClick}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
{!hideDropdownArrow && !disabled && <ChevronDown className="h-3 w-3" aria-hidden="true" />}
|
{!hideDropdownArrow && !disabled && <ChevronDown className="h-3 w-3" aria-hidden="true" />}
|
||||||
</button>
|
</button>
|
||||||
</Combobox.Button>
|
</Combobox.Button>
|
||||||
|
|
||||||
<Combobox.Options className="fixed z-10">
|
{isOpen && (
|
||||||
<div
|
<Combobox.Options className="fixed z-10" static>
|
||||||
className={`z-10 my-1 w-48 whitespace-nowrap rounded border border-custom-border-300 bg-custom-background-100 px-2 py-2.5 text-xs shadow-custom-shadow-rg focus:outline-none ${optionsClassName}`}
|
<div
|
||||||
ref={setPopperElement}
|
className={`z-10 my-1 w-48 whitespace-nowrap rounded border border-custom-border-300 bg-custom-background-100 px-2 py-2.5 text-xs shadow-custom-shadow-rg focus:outline-none ${optionsClassName}`}
|
||||||
style={styles.popper}
|
ref={setPopperElement}
|
||||||
{...attributes.popper}
|
style={styles.popper}
|
||||||
>
|
{...attributes.popper}
|
||||||
<div className="flex w-full items-center justify-start rounded border border-custom-border-200 bg-custom-background-90 px-2">
|
>
|
||||||
<Search className="h-3.5 w-3.5 text-custom-text-300" />
|
<div className="flex w-full items-center justify-start rounded border border-custom-border-200 bg-custom-background-90 px-2">
|
||||||
<Combobox.Input
|
<Search className="h-3.5 w-3.5 text-custom-text-300" />
|
||||||
className="w-full bg-transparent px-2 py-1 text-xs text-custom-text-200 placeholder:text-custom-text-400 focus:outline-none"
|
<Combobox.Input
|
||||||
value={query}
|
ref={inputRef}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
className="w-full bg-transparent px-2 py-1 text-xs text-custom-text-200 placeholder:text-custom-text-400 focus:outline-none"
|
||||||
placeholder="Search"
|
value={query}
|
||||||
displayValue={(assigned: any) => assigned?.name || ""}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
/>
|
placeholder="Search"
|
||||||
|
displayValue={(assigned: any) => assigned?.name || ""}
|
||||||
|
onKeyDown={searchInputKeyDown}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className={`mt-2 max-h-48 space-y-1 overflow-y-scroll`}>
|
||||||
|
{isLoading ? (
|
||||||
|
<p className="text-center text-custom-text-200">Loading...</p>
|
||||||
|
) : filteredOptions.length > 0 ? (
|
||||||
|
filteredOptions.map((option) => (
|
||||||
|
<Combobox.Option
|
||||||
|
key={option.value}
|
||||||
|
value={option.value}
|
||||||
|
className={({ active, selected }) =>
|
||||||
|
`flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 hover:bg-custom-background-80 ${
|
||||||
|
active ? "bg-custom-background-80" : ""
|
||||||
|
} ${selected ? "text-custom-text-100" : "text-custom-text-200"}`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{({ selected }) => (
|
||||||
|
<>
|
||||||
|
{option.content}
|
||||||
|
{selected && (
|
||||||
|
<div className="flex-shrink-0">
|
||||||
|
<Check className={`h-3.5 w-3.5`} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Combobox.Option>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<span className="flex items-center gap-2 p-1">
|
||||||
|
<p className="text-left text-custom-text-200 ">No matching results</p>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={`mt-2 max-h-48 space-y-1 overflow-y-scroll`}>
|
</Combobox.Options>
|
||||||
{isLoading ? (
|
)}
|
||||||
<p className="text-center text-custom-text-200">Loading...</p>
|
|
||||||
) : filteredOptions.length > 0 ? (
|
|
||||||
filteredOptions.map((option) => (
|
|
||||||
<Combobox.Option
|
|
||||||
key={option.value}
|
|
||||||
value={option.value}
|
|
||||||
className={({ active, selected }) =>
|
|
||||||
`flex cursor-pointer select-none items-center justify-between gap-2 truncate rounded px-1 py-1.5 hover:bg-custom-background-80 ${
|
|
||||||
active ? "bg-custom-background-80" : ""
|
|
||||||
} ${selected ? "text-custom-text-100" : "text-custom-text-200"}`
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{({ selected }) => (
|
|
||||||
<>
|
|
||||||
{option.content}
|
|
||||||
{selected && (
|
|
||||||
<div className="flex-shrink-0">
|
|
||||||
<Check className={`h-3.5 w-3.5`} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Combobox.Option>
|
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<span className="flex items-center gap-2 p-1">
|
|
||||||
<p className="text-left text-custom-text-200 ">No matching results</p>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Combobox.Options>
|
|
||||||
</Combobox>
|
</Combobox>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -187,6 +187,7 @@ const IssueRowDetails = observer((props: IssueRowDetailsProps) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<td
|
<td
|
||||||
|
id={`issue-${issueDetail.id}`}
|
||||||
className={cn(
|
className={cn(
|
||||||
"sticky group left-0 h-11 w-[28rem] flex items-center bg-custom-background-100 text-sm after:absolute border-r-[0.5px] z-[1] border-custom-border-200",
|
"sticky group left-0 h-11 w-[28rem] flex items-center bg-custom-background-100 text-sm after:absolute border-r-[0.5px] z-[1] border-custom-border-200",
|
||||||
{
|
{
|
||||||
@ -244,7 +245,7 @@ const IssueRowDetails = observer((props: IssueRowDetailsProps) => {
|
|||||||
<div className="w-full overflow-hidden">
|
<div className="w-full overflow-hidden">
|
||||||
<Tooltip tooltipHeading="Title" tooltipContent={issueDetail.name}>
|
<Tooltip tooltipHeading="Title" tooltipContent={issueDetail.name}>
|
||||||
<div
|
<div
|
||||||
className="h-full w-full cursor-pointer truncate px-4 py-2.5 text-left text-[0.825rem] text-custom-text-100"
|
className="h-full w-full cursor-pointer truncate px-4 py-2.5 text-left text-[0.825rem] text-custom-text-100 focus:outline-none"
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
>
|
>
|
||||||
{issueDetail.name}
|
{issueDetail.name}
|
||||||
|
@ -60,7 +60,13 @@ export const IssueView: FC<IIssueView> = observer((props) => {
|
|||||||
removeRoutePeekId();
|
removeRoutePeekId();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const handleKeyDown = () => !isAnyModalOpen && removeRoutePeekId();
|
const handleKeyDown = () => {
|
||||||
|
if (!isAnyModalOpen) {
|
||||||
|
removeRoutePeekId();
|
||||||
|
const issueElement = document.getElementById(`issue-${issueId}`);
|
||||||
|
if (issueElement) issueElement?.focus();
|
||||||
|
}
|
||||||
|
};
|
||||||
useKeypress("Escape", handleKeyDown);
|
useKeypress("Escape", handleKeyDown);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user