refactor(about): Use button component

- tooltip accessibility improvements
This commit is contained in:
alexsparkes
2024-05-20 09:15:50 +01:00
parent 895f61bd70
commit 0a94a27f4e
6 changed files with 136 additions and 81 deletions

View File

@@ -1,10 +1,11 @@
import { useState, memo } from 'react';
import { useState, memo, useRef } from 'react';
import { useFloating, flip, offset, shift } from '@floating-ui/react-dom';
import './tooltip.scss';
function Tooltip({ children, title, style, placement, subtitle }) {
const [showTooltip, setShowTooltip] = useState(false);
const [reference, setReference] = useState(null);
const tooltipId = useRef(`tooltip-${Math.random()}`);
const { x, y, refs, strategy } = useFloating({
placement: placement || 'bottom',
@@ -24,6 +25,7 @@ function Tooltip({ children, title, style, placement, subtitle }) {
onFocus={() => setShowTooltip(true)}
onBlur={() => setShowTooltip(false)}
ref={setReference}
aria-describedby={tooltipId.current}
>
{children}
</div>