From 19360d23437cd6e9b4def534edcd95a66c9cfffe Mon Sep 17 00:00:00 2001 From: BogdanCerovac Date: Sun, 4 Aug 2024 14:38:41 +0200 Subject: [PATCH 1/4] Add accessibility name (aria-label) to the component + add support for aria-labelledby naming --- src/Range.tsx | 6 ++++++ src/types.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Range.tsx b/src/Range.tsx index 3c8dd26..9699fd2 100644 --- a/src/Range.tsx +++ b/src/Range.tsx @@ -24,6 +24,8 @@ const DECREASE_KEYS = ["ArrowLeft", "ArrowDown", "j", "PageDown"]; class Range extends React.Component { static defaultProps = { + label: "Accessibility label", + labelledBy: null, step: 1, direction: Direction.Right, rtl: false, @@ -619,6 +621,8 @@ class Range extends React.Component { render() { const { + label, + labelledBy, renderTrack, renderThumb, renderMark = () => null, @@ -700,6 +704,8 @@ class Range extends React.Component { "aria-valuenow": value, draggable: false, ref: this.thumbRefs[index], + "aria-label" : label, + "aria-labelledby" : labelledBy, role: "slider", onKeyDown: disabled ? voidFn : this.onKeyDown, onKeyUp: disabled ? voidFn : this.onKeyUp, diff --git a/src/types.ts b/src/types.ts index 4199a06..80aab46 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,6 +9,8 @@ export interface ITrackBackground { rtl?: boolean; } export interface IProps { + label: string, + labelledBy: string, values: number[]; min: number; max: number; @@ -48,6 +50,8 @@ export interface IThumbProps { key: number; style: React.CSSProperties; tabIndex?: number; + "aria-label": string, + "aria-labelledby": string, "aria-valuemax": number; "aria-valuemin": number; "aria-valuenow": number; From 2b3068e69a2431abbe7b5f51a2aa742490eaf63c Mon Sep 17 00:00:00 2001 From: BogdanCerovac Date: Sun, 4 Aug 2024 14:44:57 +0200 Subject: [PATCH 2/4] Example on how we can use it with a visible label Using