diff --git a/packages/pluggableWidgets/color-picker-native/CHANGELOG.md b/packages/pluggableWidgets/color-picker-native/CHANGELOG.md index 84f5fb6b2..0d0a29282 100644 --- a/packages/pluggableWidgets/color-picker-native/CHANGELOG.md +++ b/packages/pluggableWidgets/color-picker-native/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We added screen reader label properties for the hue, saturation, brightness and transparency sliders. + ### Changed - We updated tinycolor2 to 1.6.0. diff --git a/packages/pluggableWidgets/color-picker-native/package.json b/packages/pluggableWidgets/color-picker-native/package.json index 128f09f13..823bf544b 100644 --- a/packages/pluggableWidgets/color-picker-native/package.json +++ b/packages/pluggableWidgets/color-picker-native/package.json @@ -1,7 +1,7 @@ { "name": "color-picker-native", "widgetName": "ColorPicker", - "version": "2.4.0", + "version": "2.4.1", "license": "Apache-2.0", "repository": { "type": "git", diff --git a/packages/pluggableWidgets/color-picker-native/src/ColorPicker.editorConfig.ts b/packages/pluggableWidgets/color-picker-native/src/ColorPicker.editorConfig.ts index e4f4364c7..3ef2c9a1f 100644 --- a/packages/pluggableWidgets/color-picker-native/src/ColorPicker.editorConfig.ts +++ b/packages/pluggableWidgets/color-picker-native/src/ColorPicker.editorConfig.ts @@ -1,4 +1,5 @@ import { StructurePreviewProps } from "@mendix/piw-utils-internal"; +import { hidePropertiesIn, Properties } from "@mendix/pluggable-widgets-tools"; import { ColorPickerPreviewProps } from "../typings/ColorPickerProps"; import colorPickerSvgNoPreviewDark from "./assets/ColorPicker.nopreview.dark.svg"; @@ -22,3 +23,10 @@ export function getPreview(values: ColorPickerPreviewProps, isDarkMode: boolean) width: 188 }; } + +export function getProperties(values: ColorPickerPreviewProps, defaultProperties: Properties): Properties { + if (!values.enableAccessibility) { + hidePropertiesIn(defaultProperties, values, ["hueLabel", "saturationLabel", "lightnessLabel", "alphaLabel"]); + } + return defaultProperties; +} diff --git a/packages/pluggableWidgets/color-picker-native/src/ColorPicker.tsx b/packages/pluggableWidgets/color-picker-native/src/ColorPicker.tsx index f4372e5bd..598a23d86 100644 --- a/packages/pluggableWidgets/color-picker-native/src/ColorPicker.tsx +++ b/packages/pluggableWidgets/color-picker-native/src/ColorPicker.tsx @@ -110,6 +110,7 @@ export function ColorPicker(props: Props): ReactElement | null { )} - + + Color picker Pick a color from a circular color input Input elements @@ -14,7 +11,7 @@ Color Attribute containing a valid color like #d0d0d0, red, rgba(255,255,255,0). - + @@ -47,6 +44,28 @@ Enables a slider to make the color more transparent or opaque. + + + Custom accessibility labels + Enables setting custom screen reader labels for the sliders. + + + Hue label + Screen reader label of the hue slider. Defaults to "Hue". + + + Saturation label + Screen reader label of the saturation slider. Defaults to "Saturation". + + + Brightness label + Screen reader label of the brightness slider. Defaults to "Brightness". + + + Transparency label + Screen reader label of the transparency slider. Defaults to "Transparency". + + On change @@ -55,7 +74,7 @@ - + diff --git a/packages/pluggableWidgets/color-picker-native/src/__tests__/ColorPicker.spec.tsx b/packages/pluggableWidgets/color-picker-native/src/__tests__/ColorPicker.spec.tsx index db85160af..c467986dc 100644 --- a/packages/pluggableWidgets/color-picker-native/src/__tests__/ColorPicker.spec.tsx +++ b/packages/pluggableWidgets/color-picker-native/src/__tests__/ColorPicker.spec.tsx @@ -1,4 +1,5 @@ import { actionValue, EditableValueBuilder } from "@mendix/piw-utils-internal"; +import { DynamicValue, ValueStatus } from "mendix"; import { View } from "react-native"; import { fireEvent, render, RenderAPI } from "@testing-library/react-native"; import { ReactTestInstance } from "react-test-renderer"; @@ -17,7 +18,8 @@ describe("Color Picker", () => { showPreview: true, showSaturation: true, showLightness: true, - showAlpha: false + showAlpha: false, + enableAccessibility: false }; }); @@ -222,6 +224,34 @@ describe("Color Picker", () => { }); }); + it("labels the sliders for screen readers", () => { + const label = (value: string): DynamicValue => ({ status: ValueStatus.Available, value }); + const component = render( + + ); + + const labelOf = (name: string): string => + component.getByTestId(`color-picker-test$${name}`).props.accessibilityLabel; + expect(labelOf("hue")).toBe("Tint"); + expect(labelOf("saturation")).toBe("Intensity"); + expect(labelOf("lightness")).toBe("Brightness"); + expect(labelOf("alpha")).toBe("Transparency"); + }); + + it("ignores custom labels when accessibility is not enabled", () => { + const label = (value: string): DynamicValue => ({ status: ValueStatus.Available, value }); + const component = render(); + + expect(component.getByTestId("color-picker-test$hue").props.accessibilityLabel).toBe("Hue"); + }); + it("changes the value with screen reader actions", () => { const onChangeAction = actionValue(); const component = render(); diff --git a/packages/pluggableWidgets/color-picker-native/src/__tests__/__snapshots__/ColorPicker.spec.tsx.snap b/packages/pluggableWidgets/color-picker-native/src/__tests__/__snapshots__/ColorPicker.spec.tsx.snap index 6c301bd8b..34f5a5531 100644 --- a/packages/pluggableWidgets/color-picker-native/src/__tests__/__snapshots__/ColorPicker.spec.tsx.snap +++ b/packages/pluggableWidgets/color-picker-native/src/__tests__/__snapshots__/ColorPicker.spec.tsx.snap @@ -1118,6 +1118,7 @@ exports[`Color Picker renders 1`] = ` }, ] } + accessibilityLabel="Hue" accessibilityRole="adjustable" accessibilityState={ { @@ -2330,6 +2331,7 @@ exports[`Color Picker renders 1`] = ` }, ] } + accessibilityLabel="Saturation" accessibilityRole="adjustable" accessibilityState={ { @@ -3542,6 +3544,7 @@ exports[`Color Picker renders 1`] = ` }, ] } + accessibilityLabel="Brightness" accessibilityRole="adjustable" accessibilityState={ { @@ -4776,6 +4779,7 @@ exports[`Color Picker renders with alpha slider 1`] = ` }, ] } + accessibilityLabel="Hue" accessibilityRole="adjustable" accessibilityState={ { @@ -5988,6 +5992,7 @@ exports[`Color Picker renders with alpha slider 1`] = ` }, ] } + accessibilityLabel="Saturation" accessibilityRole="adjustable" accessibilityState={ { @@ -7200,6 +7205,7 @@ exports[`Color Picker renders with alpha slider 1`] = ` }, ] } + accessibilityLabel="Brightness" accessibilityRole="adjustable" accessibilityState={ { @@ -8412,6 +8418,7 @@ exports[`Color Picker renders with alpha slider 1`] = ` }, ] } + accessibilityLabel="Transparency" accessibilityRole="adjustable" accessibilityState={ { @@ -9647,6 +9654,7 @@ exports[`Color Picker renders with custom style 1`] = ` }, ] } + accessibilityLabel="Hue" accessibilityRole="adjustable" accessibilityState={ { @@ -10859,6 +10867,7 @@ exports[`Color Picker renders with custom style 1`] = ` }, ] } + accessibilityLabel="Saturation" accessibilityRole="adjustable" accessibilityState={ { @@ -12071,6 +12080,7 @@ exports[`Color Picker renders with custom style 1`] = ` }, ] } + accessibilityLabel="Brightness" accessibilityRole="adjustable" accessibilityState={ { diff --git a/packages/pluggableWidgets/color-picker-native/src/components/PickerSlider.tsx b/packages/pluggableWidgets/color-picker-native/src/components/PickerSlider.tsx index bb91f9b6f..072c6c32a 100644 --- a/packages/pluggableWidgets/color-picker-native/src/components/PickerSlider.tsx +++ b/packages/pluggableWidgets/color-picker-native/src/components/PickerSlider.tsx @@ -14,6 +14,7 @@ interface PickerSlidersProps { trackStyle?: ViewStyle; disabled?: boolean; testID?: string; + accessibilityLabel?: string; } export function PickerSlider(props: PropsWithChildren): ReactElement { @@ -22,6 +23,7 @@ export function PickerSlider(props: PropsWithChildren): Reac {props.children} - + diff --git a/packages/pluggableWidgets/color-picker-native/typings/ColorPickerProps.d.ts b/packages/pluggableWidgets/color-picker-native/typings/ColorPickerProps.d.ts index fdf2e2203..41aa4b994 100644 --- a/packages/pluggableWidgets/color-picker-native/typings/ColorPickerProps.d.ts +++ b/packages/pluggableWidgets/color-picker-native/typings/ColorPickerProps.d.ts @@ -3,7 +3,7 @@ * WARNING: All changes made to this file will be overwritten * @author Mendix Widgets Framework Team */ -import { ActionValue, EditableValue } from "mendix"; +import { ActionValue, DynamicValue, EditableValue } from "mendix"; import { CSSProperties } from "react"; export type FormatEnum = "hex" | "hsl" | "hsv" | "rgb"; @@ -17,6 +17,11 @@ export interface ColorPickerProps