(function
{validData.map((item, i) => (
setHoveredIndex(i)}
+ onMouseEnter={() => handleLegendEnter(i)}
onMouseLeave={() => setHoveredIndex(null)}
className={cn(
'flex items-center gap-2 transition-opacity duration-200 cursor-default',
diff --git a/src/dashkit/PieChart/usePieChart.ts b/src/dashkit/PieChart/usePieChart.ts
index fff2fbc7..d7c77ddb 100644
--- a/src/dashkit/PieChart/usePieChart.ts
+++ b/src/dashkit/PieChart/usePieChart.ts
@@ -21,6 +21,7 @@ export function usePieChart({ data, innerRadius, showTooltip }: UsePieChartProps
slices: [],
handleMouseMove: () => {},
handleTouchMove: () => {},
+ handleLegendEnter: () => {},
isNearTop: false,
total: 0,
size: 400,
@@ -115,7 +116,26 @@ export function usePieChart({ data, innerRadius, showTooltip }: UsePieChartProps
}
};
- const isNearTop = tooltipPos.y < 100;
+ const handleLegendEnter = (index: number) => {
+ setHoveredIndex(index);
+ const slice = slices[index];
+ if (!showTooltip || !slice || !containerRef.current) return;
+
+ const rect = containerRef.current.getBoundingClientRect();
+ if (rect.width === 0 || rect.height === 0) return;
+
+ const midAngle = (slice.startAngle + slice.endAngle) / 2;
+ const midRadius = (radius + holeRadius) / 2;
+ const svgX = center + midRadius * Math.cos(midAngle);
+ const svgY = center + midRadius * Math.sin(midAngle);
+
+ setTooltipPos({
+ x: (svgX / size) * rect.width,
+ y: (svgY / size) * rect.height
+ });
+ };
+
+ const isNearTop = tooltipPos.y < 72;
return {
hoveredIndex,
@@ -125,6 +145,7 @@ export function usePieChart({ data, innerRadius, showTooltip }: UsePieChartProps
slices,
handleMouseMove,
handleTouchMove,
+ handleLegendEnter,
isNearTop,
total,
size,
diff --git a/src/dashkit/Popover/PopoverContent.tsx b/src/dashkit/Popover/PopoverContent.tsx
index ec0e53df..6bff24f8 100644
--- a/src/dashkit/Popover/PopoverContent.tsx
+++ b/src/dashkit/Popover/PopoverContent.tsx
@@ -124,6 +124,7 @@ export const PopoverContent = React.forwardRef;
onMouseEnter?: React.MouseEventHandler;
onMouseLeave?: React.MouseEventHandler;
+ 'aria-expanded'?: boolean;
+ 'aria-haspopup'?: 'dialog';
}>, {
ref: internalRef,
+ 'aria-expanded': open,
+ 'aria-haspopup': 'dialog',
onClick: (e: React.MouseEvent) => {
(children.props as { onClick?: React.MouseEventHandler }).onClick?.(e);
toggleOpen(e.currentTarget as HTMLElement);
@@ -93,7 +97,7 @@ export function PopoverTrigger({ children, asChild }: PopoverTriggerProps) {
onMouseLeave={onMouseLeave}
onFocus={onFocus}
onBlur={onBlur}
- className="cursor-pointer inline-block"
+ className="cursor-pointer inline-block rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
{children}
diff --git a/src/dashkit/ProgressBar/ProgressBar.tsx b/src/dashkit/ProgressBar/ProgressBar.tsx
index 13521989..c1765c67 100644
--- a/src/dashkit/ProgressBar/ProgressBar.tsx
+++ b/src/dashkit/ProgressBar/ProgressBar.tsx
@@ -1,4 +1,5 @@
import * as React from 'react';
+import { useId } from 'react';
import { motion } from 'framer-motion';
import { cva } from 'class-variance-authority';
import { cn } from '../utils/cn';
@@ -85,6 +86,7 @@ export const ProgressBar = React.forwardRef
(
...props
}, ref) => {
const { percentage } = useProgressBar({ value, max });
+ const labelId = useId();
const BarContainer = (
(
aria-valuenow={Math.round(percentage)}
aria-valuemin={0}
aria-valuemax={100}
+ aria-labelledby={label ? labelId : undefined}
data-testid="progress-bar-track"
className={cn(progressTrackVariants({ position: labelPosition, size }))}
>
@@ -122,7 +125,7 @@ export const ProgressBar = React.forwardRef
(
{BarContainer}
{(showLabel || label) && (
- {label &&
{label}}
+ {label &&
{label}}
{showLabel && (
{Math.round(percentage)}%
@@ -143,7 +146,7 @@ export const ProgressBar = React.forwardRef(
>
{(showLabel || label) && (
- {label &&
{label}}
+ {label &&
{label}}
{showLabel && (
{Math.round(percentage)}%
diff --git a/src/dashkit/ProgressBar/useProgressBar.ts b/src/dashkit/ProgressBar/useProgressBar.ts
index e3c29418..6b3df2b3 100644
--- a/src/dashkit/ProgressBar/useProgressBar.ts
+++ b/src/dashkit/ProgressBar/useProgressBar.ts
@@ -4,7 +4,8 @@ export interface UseProgressBarProps {
}
export function useProgressBar({ value, max }: UseProgressBarProps) {
- const percentage = Math.min(Math.max((value / max) * 100, 0), 100);
+ const safeMax = max > 0 ? max : 100;
+ const percentage = Math.min(Math.max((value / safeMax) * 100, 0), 100);
return {
percentage
diff --git a/src/dashkit/Radio/Radio.test.tsx b/src/dashkit/Radio/Radio.test.tsx
index 02b166d6..42c35c93 100644
--- a/src/dashkit/Radio/Radio.test.tsx
+++ b/src/dashkit/Radio/Radio.test.tsx
@@ -41,11 +41,11 @@ describe('Radio', () => {
expect(container).toHaveClass('opacity-50');
});
- it('generates an ID automatically from label if not provided', () => {
+ it('generates a unique ID automatically when not provided', () => {
render();
const label = screen.getByText(/My Radio/i);
const input = screen.getByRole('radio');
- expect(input.id).toBe('radio-my-radio');
- expect(label.parentElement).toHaveAttribute('for', 'radio-my-radio');
+ expect(input.id).toBeTruthy();
+ expect(label.closest('label')).toHaveAttribute('for', input.id);
});
});
diff --git a/src/dashkit/Radio/Radio.tsx b/src/dashkit/Radio/Radio.tsx
index 582b90b4..bedce175 100644
--- a/src/dashkit/Radio/Radio.tsx
+++ b/src/dashkit/Radio/Radio.tsx
@@ -16,8 +16,10 @@ export interface RadioProps extends Omit,
* ```
*/
export const Radio = forwardRef(
- ({ label, description, className, id, ...props }, ref) => {
- const { radioId } = useRadio({ id, label });
+ function Radio({ label, description, className, id, ...props }, ref) {
+ const { radioId } = useRadio({ id });
+ const descriptionId = description ? `${radioId}-description` : undefined;
+ const describedBy = [props['aria-describedby'], descriptionId].filter(Boolean).join(' ') || undefined;
return (
(
type="radio"
id={radioId}
ref={ref}
+ aria-describedby={describedBy}
className="peer sr-only"
/>
(
{(label || description) && (
-
);
diff --git a/src/dashkit/Radio/useRadio.ts b/src/dashkit/Radio/useRadio.ts
index b3ff86b3..a65ba598 100644
--- a/src/dashkit/Radio/useRadio.ts
+++ b/src/dashkit/Radio/useRadio.ts
@@ -1,10 +1,12 @@
+import { useId } from 'react';
+
export interface UseRadioProps {
id?: string;
- label?: string;
}
-export function useRadio({ id, label }: UseRadioProps) {
- const radioId = id || (label ? `radio-${label.toLowerCase().replace(/\s+/g, '-')}` : undefined);
+export function useRadio({ id }: UseRadioProps) {
+ const generatedId = useId();
+ const radioId = id || `radio-${generatedId}`;
return {
radioId
diff --git a/src/dashkit/ScrollArea/ScrollArea.tsx b/src/dashkit/ScrollArea/ScrollArea.tsx
index 15e1004d..4416d2c6 100644
--- a/src/dashkit/ScrollArea/ScrollArea.tsx
+++ b/src/dashkit/ScrollArea/ScrollArea.tsx
@@ -52,7 +52,15 @@ export const ScrollArea = forwardRef(function S
className={cn('relative overflow-hidden w-full h-full', className)}
{...props}
>
-
diff --git a/src/dashkit/Select/Select.tsx b/src/dashkit/Select/Select.tsx
index 69151a9a..fb382515 100644
--- a/src/dashkit/Select/Select.tsx
+++ b/src/dashkit/Select/Select.tsx
@@ -109,6 +109,7 @@ export const Select = forwardRef(
);
const labelId = useId();
+ const triggerId = useId();
const valueId = useId();
const listId = useId();
const messageId = useId();
@@ -122,13 +123,19 @@ export const Select = forwardRef(
className="flex flex-col gap-1.5 w-full font-sans"
>
{label && (
-
+
{label}
)}