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,13 +20,18 @@ 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);
selector.setValue(newSelection);
}
};

const isSingleCheckbox = options.length === 1;

return (
<div
className={classNames("widget-checkbox-radio-selection-list", {
Expand All @@ -34,6 +41,8 @@ export function CheckboxSelection({
role="group"
aria-labelledby={`${inputId}-label`}
aria-required={ariaRequired?.value}
aria-describedby={!isSingleCheckbox && selector.validation ? errorId : undefined}
aria-invalid={!isSingleCheckbox && selector.validation ? true : undefined}
>
{options.map((optionId, index) => {
const isSelected = currentIds.includes(optionId);
Expand All @@ -55,6 +64,8 @@ export function CheckboxSelection({
disabled={isReadOnly}
tabIndex={tabIndex}
onChange={e => handleChange(optionId, e.target.checked)}
aria-describedby={isSingleCheckbox && selector.validation ? errorId : undefined}
aria-invalid={isSingleCheckbox && selector.validation ? true : undefined}
/>
<CaptionContent
onClick={(e: MouseEvent<HTMLDivElement>) => {
Expand All @@ -71,6 +82,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 All @@ -45,6 +50,8 @@ export function RadioSelection({
role={asSingleCheckbox ? "group" : "radiogroup"}
aria-labelledby={`${inputId}-label`}
aria-required={ariaRequired?.value}
aria-describedby={!asSingleCheckbox && selector.validation ? errorId : undefined}
aria-invalid={!asSingleCheckbox && selector.validation ? true : undefined}
>
{options.map((optionId, index) => {
const isSelected = currentId === optionId;
Expand All @@ -70,6 +77,8 @@ export function RadioSelection({
disabled={isReadOnly}
tabIndex={tabIndex}
onChange={handleChange}
aria-describedby={asSingleCheckbox && selector.validation ? errorId : undefined}
aria-invalid={asSingleCheckbox && selector.validation ? true : undefined}
/>
</If>
<CaptionContent
Expand All @@ -89,6 +98,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