Skip to content

Commit bc21742

Browse files
Add focus ring for <SelectableCardSolid> (#17352)
* Add focus ring for `<SelectableCardSolid>` * Fix Selectable card focus * Make radio input aria-labelled
1 parent 0f316da commit bc21742

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

components/dashboard/src/components/SelectableCardSolid.tsx

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7+
import { useState } from "react";
8+
79
export interface SelectableCardSolidProps {
810
title: string;
911
selected: boolean;
@@ -13,9 +15,21 @@ export interface SelectableCardSolidProps {
1315
}
1416

1517
function SelectableCardSolid(props: SelectableCardSolidProps) {
18+
const [isFocused, setIsFocused] = useState(false);
19+
20+
const handleFocus = () => {
21+
setIsFocused(true);
22+
};
23+
24+
const handleBlur = () => {
25+
setIsFocused(false);
26+
};
27+
1628
return (
1729
<div
1830
className={`rounded-xl px-3 py-3 flex flex-col cursor-pointer group transition ease-in-out ${
31+
isFocused ? "ring-2 ring-blue-500" : ""
32+
} ${
1933
props.selected
2034
? "bg-gray-800 dark:bg-gray-100"
2135
: "bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700"
@@ -31,7 +45,14 @@ function SelectableCardSolid(props: SelectableCardSolidProps) {
3145
>
3246
{props.title}
3347
</p>
34-
<input className="opacity-0" type="radio" checked={props.selected} />
48+
<input
49+
className="opacity-0"
50+
type="radio"
51+
checked={props.selected}
52+
onFocus={handleFocus}
53+
onBlur={handleBlur}
54+
aria-label={props.title}
55+
/>
3556
</div>
3657
{props.children}
3758
</div>

0 commit comments

Comments
 (0)