Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Added

- We added a missing validation alert.

## [1.0.0] - 2025-08-25

### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import classNames from "classnames";
import { createElement, MouseEvent, ReactElement } from "react";
import { MultiSelector, SelectionBaseProps } from "../../helpers/types";
import { getValidationErrorId } from "../../helpers/utils";
import { CaptionContent } from "../CaptionContent";
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
import { Placeholder } from "../Placeholder";

export function CheckboxSelection({
Expand All @@ -18,6 +20,9 @@ export function CheckboxSelection({
const isReadOnly = selector.readOnly;
const name = groupName?.value ?? inputId;

const validation = selector.validation;
const errorId = getValidationErrorId(inputId);

const handleChange = (optionId: string, checked: boolean): void => {
if (!isReadOnly) {
const newSelection = checked ? [...currentIds, optionId] : currentIds.filter(id => id !== optionId);
Expand Down Expand Up @@ -55,6 +60,8 @@ export function CheckboxSelection({
disabled={isReadOnly}
tabIndex={tabIndex}
onChange={e => handleChange(optionId, e.target.checked)}
aria-describedby={selector.validation ? errorId : undefined}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

difference with combobox,
i think aria-describeby and aria-invalid should be on the component with radiogroup role. not on each input.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/radiogroup_role

@HedwigAR please confirm.

aria-invalid={selector.validation ? true : undefined}
/>
<CaptionContent
onClick={(e: MouseEvent<HTMLDivElement>) => {
Expand All @@ -71,6 +78,7 @@ export function CheckboxSelection({
);
})}
{options.length === 0 && <Placeholder noOptionsText={noOptionsText} />}
{validation && <ValidationAlert id={errorId}>{validation}</ValidationAlert>}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import classNames from "classnames";
import { ChangeEvent, createElement, MouseEvent, ReactElement } from "react";
import { SelectionBaseProps, SingleSelector } from "../../helpers/types";
import { getValidationErrorId } from "../../helpers/utils";
import { CaptionContent } from "../CaptionContent";
import { ValidationAlert } from "@mendix/widget-plugin-component-kit/Alert";
import { Placeholder } from "../Placeholder";
import { If } from "@mendix/widget-plugin-component-kit/If";

Expand All @@ -24,6 +26,9 @@ export function RadioSelection({
const isReadOnly = selector.readOnly;
const name = groupName?.value ?? inputId;

const validation = selector.validation;
const errorId = getValidationErrorId(inputId);

const handleChange = (e: ChangeEvent<HTMLInputElement>): void => {
if (isReadOnly) {
return;
Expand Down Expand Up @@ -70,6 +75,8 @@ export function RadioSelection({
disabled={isReadOnly}
tabIndex={tabIndex}
onChange={handleChange}
aria-describedby={selector.validation ? errorId : undefined}
aria-invalid={selector.validation ? true : undefined}
/>
</If>
<CaptionContent
Expand All @@ -89,6 +96,7 @@ export function RadioSelection({
);
})}
{options.length === 0 && <Placeholder noOptionsText={noOptionsText} />}
{validation && <ValidationAlert id={errorId}>{validation}</ValidationAlert>}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ export function getCustomCaption(values: CheckboxRadioSelectionPreviewProps): st
}
return emptyStringFormat;
}

export function getValidationErrorId(inputId?: string): string | undefined {
return inputId ? inputId + "-validation-message" : undefined;
}
Loading