Skip to content
Components, switch product

Errors

<gui-errors> is the error list of a GolemUI Components field as an element of its own, styled like every other field’s errors. Use it under a control you build yourself, together with a gui-label. The fields render their own errors, so you rarely need it next to them.

Code of the example above
PartsCustomField.tsx
import { useState } from 'react';
import { GuiErrors, GuiLabel } from '@golemui/gui-components/react';
import '@golemui/gui-components/index.css';
const errors = ['Pick a darker color for enough contrast.'];
export function PartsCustomField() {
const [input, setInput] = useState<HTMLInputElement | null>(null);
return (
<div className="gui-field">
{/* The label sets the input's ARIA attributes: describedby, invalid, required. */}
<GuiLabel
uid="brand-color"
label="Brand color"
hint="Used for buttons and links."
required
targetElement={input ?? undefined}
errors={errors}
/>
<div className="gui-widget">
<input
ref={setInput}
id="brand-color"
type="color"
defaultValue="#b5531f"
/>
</div>
<GuiErrors uid="brand-color" errors={errors} />
</div>
);
}
import '@golemui/gui-components/errors';

Give it the same uid as your control’s id. Its container gets the id <uid>_errors, which a gui-label pointed at the control links with aria-errormessage.

Set errors to a list of messages: as an attribute, a JSON array. An empty list clears them. touched holds the errors back while it is false; leave it unset to show them as soon as you set them. panel styles the list for a popup instead of under a field.

Properties

Property Type Default Description
errors string[] [] The error messages.
touched boolean – Whether the control was touched: errors wait for it unless unset.
panel boolean false Renders the errors inside a popup panel instead of under a field.
uid string – The id of the element's control. The ids of its label, hint and errors derive from it. Optional: when it is not set, the element generates one from its tag name and a page-wide counter, e.g. gui-textinput-3. Generated ids depend on creation order, so a server-rendered element must set uid or its ids will not match after hydration.
idPrefix attribute id-prefix string – Goes in front of every DOM id the element renders, so two elements with the same uid in different forms render different ids. GolemUI Forms sets it to the form's formName. Only ids and the references to them (for, aria-describedby…) take it: data-cy attributes and event details keep the bare uid.
domId read-only, no attribute string – The id of the element's control: uid, behind idPrefix when it is set.

The container is always in the page, with the alert role, so screen readers announce each new error as it appears.

ClassPart
gui-validatorThe errors container. It is always there, so the alert role announces new errors.
gui-validator__errorOne error message.