Always show species face tooltip in keyboard nav

This commit is contained in:
Emi Matchu 2021-02-02 15:43:36 -08:00
parent cdff51dfef
commit 28f457e21f

View file

@ -844,18 +844,20 @@ function SpeciesFaceOption({
]);
const xlShadow = useToken("shadows", "xl");
const [labelIsHovered, setLabelIsHovered] = React.useState(false);
const [inputIsFocused, setInputIsFocused] = React.useState(false);
const isHappy = isLoading || isCompatible;
const emotionId = isHappy ? "1" : "2";
const tooltipLabel =
isCompatible || isLoading ? (
speciesName
) : (
const tooltipLabel = (
<div style={{ textAlign: "center" }}>
{speciesName}
{!isLoading && !isCompatible && (
<div style={{ fontStyle: "italic", fontSize: "0.75em" }}>
(Not compatible yet)
</div>
)}
</div>
);
@ -872,8 +874,18 @@ function SpeciesFaceOption({
// `pointer-events: none` to the portal container, which I
// think is intercepting the hover even if the label doesn't.
gutter={-12}
// We track hover and focus state manually for the tooltip, so that
// keyboard nav to switch between options causes the tooltip to
// follow. (By default, the tooltip appears on the first tab focus,
// but not when you _change_ options!)
isOpen={labelIsHovered || inputIsFocused}
>
<Box
as="label"
cursor={cursor}
onMouseEnter={() => setLabelIsHovered(true)}
onMouseLeave={() => setLabelIsHovered(false)}
>
<Box as="label" cursor={cursor}>
<VisuallyHidden
as="input"
type="radio"
@ -883,6 +895,8 @@ function SpeciesFaceOption({
checked={isSelected}
disabled={isLoading || !isCompatible}
onChange={() => onChange({ speciesId, colorId })}
onFocus={() => setInputIsFocused(true)}
onBlur={() => setInputIsFocused(false)}
/>
<Box
overflow="hidden"