Skip to content

Commit

Permalink
💄 (grapher) pass numeric slider values when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Feb 1, 2024
1 parent 308b7c7 commit 78da5a8
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,18 @@ const TimelineHandle = ({
onBlur?: React.FocusEventHandler<HTMLDivElement>
}): JSX.Element => {
return (
// @ts-expect-error aria-value* fields expect a number, but we're passing a string
// @ts-expect-error aria-value* fields expect a number, but if we're dealing with daily data,
// the numeric representation of a date is meaningless, so we pass the formatted date string instead.
<div
className={classNames("handle", type)}
style={{
left: `${offsetPercent}%`,
}}
role="slider"
tabIndex={0}
aria-valuemin={formattedMinTime}
aria-valuenow={formattedCurrTime}
aria-valuemax={formattedMaxTime}
aria-valuemin={castToNumberIfPossible(formattedMinTime)}
aria-valuenow={castToNumberIfPossible(formattedCurrTime)}
aria-valuemax={castToNumberIfPossible(formattedMaxTime)}
aria-label={label}
onFocus={onFocus}
onBlur={onBlur}
Expand All @@ -489,3 +490,11 @@ const TimelineHandle = ({
</div>
)
}

function castToNumberIfPossible(s: string): string | number {
return isNumber(s) ? +s : s
}

function isNumber(s: string): boolean {
return /^\d+$/.test(s)
}

0 comments on commit 78da5a8

Please sign in to comment.