Skip to content

Commit a2ae49b

Browse files
committed
fix: add accessibility labels
1 parent 1aca061 commit a2ae49b

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎packages/pluggableWidgets/color-picker-native/src/ColorPicker.editorConfig.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { StructurePreviewProps } from "@mendix/piw-utils-internal";
2+
import { hidePropertiesIn, Properties } from "@mendix/pluggable-widgets-tools";
23

34
import { ColorPickerPreviewProps } from "../typings/ColorPickerProps";
45
import colorPickerSvgNoPreviewDark from "./assets/ColorPicker.nopreview.dark.svg";
@@ -22,3 +23,10 @@ export function getPreview(values: ColorPickerPreviewProps, isDarkMode: boolean)
2223
width: 188
2324
};
2425
}
26+
27+
export function getProperties(values: ColorPickerPreviewProps, defaultProperties: Properties): Properties {
28+
if (!values.enableAccessibility) {
29+
hidePropertiesIn(defaultProperties, values, ["hueLabel", "saturationLabel", "lightnessLabel", "alphaLabel"]);
30+
}
31+
return defaultProperties;
32+
}

‎packages/pluggableWidgets/color-picker-native/src/ColorPicker.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function ColorPicker(props: Props): ReactElement | null {
110110
)}
111111
<PickerSlider
112112
testID={`${props.name}$hue`}
113-
accessibilityLabel={props.hueLabel?.value || "Hue"}
113+
accessibilityLabel={(props.enableAccessibility && props.hueLabel?.value) || "Hue"}
114114
value={color.h}
115115
onValueChange={onChangeHue}
116116
onValueChangeComplete={onChangeComplete}
@@ -129,7 +129,7 @@ export function ColorPicker(props: Props): ReactElement | null {
129129
{props.showSaturation && !colorValue.readOnly && (
130130
<PickerSlider
131131
testID={`${props.name}$saturation`}
132-
accessibilityLabel={props.saturationLabel?.value || "Saturation"}
132+
accessibilityLabel={(props.enableAccessibility && props.saturationLabel?.value) || "Saturation"}
133133
value={color.s}
134134
onValueChange={onChangeSaturation}
135135
onValueChangeComplete={onChangeComplete}
@@ -144,7 +144,7 @@ export function ColorPicker(props: Props): ReactElement | null {
144144
{props.showLightness && !colorValue.readOnly && (
145145
<PickerSlider
146146
testID={`${props.name}$lightness`}
147-
accessibilityLabel={props.lightnessLabel?.value || "Brightness"}
147+
accessibilityLabel={(props.enableAccessibility && props.lightnessLabel?.value) || "Brightness"}
148148
value={color.l}
149149
onValueChange={onChangeLightness}
150150
onValueChangeComplete={onChangeComplete}
@@ -159,7 +159,7 @@ export function ColorPicker(props: Props): ReactElement | null {
159159
{format !== "hex" && props.showAlpha && !colorValue.readOnly && (
160160
<PickerSlider
161161
testID={`${props.name}$alpha`}
162-
accessibilityLabel={props.alphaLabel?.value || "Transparency"}
162+
accessibilityLabel={(props.enableAccessibility && props.alphaLabel?.value) || "Transparency"}
163163
value={color.a}
164164
onValueChange={onChangeAlpha}
165165
onValueChangeComplete={onChangeComplete}

‎packages/pluggableWidgets/color-picker-native/src/ColorPicker.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
</property>
4646
</propertyGroup>
4747
<propertyGroup caption="Accessibility">
48+
<property key="enableAccessibility" type="boolean" defaultValue="false">
49+
<caption>Custom accessibility labels</caption>
50+
<description>Enables setting custom screen reader labels for the sliders.</description>
51+
</property>
4852
<property key="hueLabel" type="textTemplate" required="false">
4953
<caption>Hue label</caption>
5054
<description>Screen reader label of the hue slider. Defaults to "Hue".</description>

‎packages/pluggableWidgets/color-picker-native/src/__tests__/ColorPicker.spec.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ describe("Color Picker", () => {
1818
showPreview: true,
1919
showSaturation: true,
2020
showLightness: true,
21-
showAlpha: false
21+
showAlpha: false,
22+
enableAccessibility: false
2223
};
2324
});
2425

@@ -230,6 +231,7 @@ describe("Color Picker", () => {
230231
{...defaultProps}
231232
format="rgb"
232233
showAlpha
234+
enableAccessibility
233235
hueLabel={label("Tint")}
234236
saturationLabel={label("Intensity")}
235237
/>
@@ -243,6 +245,13 @@ describe("Color Picker", () => {
243245
expect(labelOf("alpha")).toBe("Transparency");
244246
});
245247

248+
it("ignores custom labels when accessibility is not enabled", () => {
249+
const label = (value: string): DynamicValue<string> => ({ status: ValueStatus.Available, value });
250+
const component = render(<ColorPicker {...defaultProps} hueLabel={label("Tint")} />);
251+
252+
expect(component.getByTestId("color-picker-test$hue").props.accessibilityLabel).toBe("Hue");
253+
});
254+
246255
it("changes the value with screen reader actions", () => {
247256
const onChangeAction = actionValue();
248257
const component = render(<ColorPicker {...defaultProps} onChange={onChangeAction} />);

‎packages/pluggableWidgets/color-picker-native/typings/ColorPickerProps.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface ColorPickerProps<Style> {
1717
showSaturation: boolean;
1818
showLightness: boolean;
1919
showAlpha: boolean;
20+
enableAccessibility: boolean;
2021
hueLabel?: DynamicValue<string>;
2122
saturationLabel?: DynamicValue<string>;
2223
lightnessLabel?: DynamicValue<string>;
@@ -41,6 +42,7 @@ export interface ColorPickerPreviewProps {
4142
showSaturation: boolean;
4243
showLightness: boolean;
4344
showAlpha: boolean;
45+
enableAccessibility: boolean;
4446
hueLabel: string;
4547
saturationLabel: string;
4648
lightnessLabel: string;

0 commit comments

Comments
 (0)