CngxRequired
projects/forms/field/required.component.ts
Import#
import { CngxRequired } from '@cngx/forms/field'
Description#
Auto-showing required indicator inside a cngx-form-field.
Renders the marker only when the field's required() signal is true.
Sets aria-hidden="true" so screen readers ignore the visual marker -
the input already communicates required state via aria-required.
Supports a custom template for rendering icons, tooltips, or styled badges.
Text marker (default)
<label cngxLabel>E-Mail <cngx-required /></label>Custom marker text
<label cngxLabel>E-Mail <cngx-required marker="(required)" /></label>Custom template (icon)
<label cngxLabel>
E-Mail
<cngx-required>
<ng-template>
<svg width="8" height="8" viewBox="0 0 8 8"><circle cx="4" cy="4" r="4" fill="currentColor"/></svg>
</ng-template>
</cngx-required>
</label>Metadata#
Host#
Relationships
Depends on1
Index#
Inputs#
The visual marker text. Defaults to *. Ignored when a custom template is provided.
'*'Instance Properties#
unknownOptional custom template. Replaces the text marker when provided.
contentChild<TemplateRef<CngxRequiredContext>>(TemplateRef)Default visuals for CngxRequired - the required marker rendered
as a standalone atom. The host carries .cngx-required and stays
inline so the marker sits next to the label text; the inner <span>
carries the glyph color.
Slots
.cngx-required- host element, keptdisplay: inlinewith a0.125eminline-start margin (display: contentswould push the inner span into the label's parent and land the asterisk on its own row in stacked-field grids)- inner
<span>- the glyph itself, colored from the danger chain
Inheritance
The required-marker token is shared with CngxLabel; redeclared
here so consumers can use <cngx-required> without also using
[cngxLabel]:
--cngx-field-required-color->--cngx-field-error-color->--cngx-color-danger
A :root delegating rule pins the token to --cngx-color-danger
so a dark-mode swap on the foundation token cascades through.
State / Required
<color>oklch(0.55 0.21 27)Color of the required-marker glyph. Falls back through
--cngx-field-error-color and then --cngx-color-danger.
See: [[--cngx-color-danger]]