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

Add focus ring for <SelectableCardSolid> #17352

Merged
merged 3 commits into from
Apr 24, 2023
Merged
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
23 changes: 22 additions & 1 deletion components/dashboard/src/components/SelectableCardSolid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useState } from "react";

export interface SelectableCardSolidProps {
title: string;
selected: boolean;
Expand All @@ -13,9 +15,21 @@ export interface SelectableCardSolidProps {
}

function SelectableCardSolid(props: SelectableCardSolidProps) {
const [isFocused, setIsFocused] = useState(false);

const handleFocus = () => {
setIsFocused(true);
};

const handleBlur = () => {
setIsFocused(false);
};

return (
<div
className={`rounded-xl px-3 py-3 flex flex-col cursor-pointer group transition ease-in-out ${
isFocused ? "ring-2 ring-blue-500" : ""
} ${
props.selected
? "bg-gray-800 dark:bg-gray-100"
: "bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
Expand All @@ -31,7 +45,14 @@ function SelectableCardSolid(props: SelectableCardSolidProps) {
>
{props.title}
</p>
<input className="opacity-0" type="radio" checked={props.selected} />
<input
className="opacity-0"
type="radio"
checked={props.selected}
onFocus={handleFocus}
onBlur={handleBlur}
aria-label={props.title}
/>
</div>
{props.children}
</div>
Expand Down