Skip to content

nve-checkbox

En avkrysningsboks. Ikke bruk `size`, i NVE bruker vi kun en størrelse på avkrysningsbokser.

Arvet fra SlCheckbox.

Denne komponenten bygger på en Shoelace-komponent. Sjekk også dokumentasjonen i Shoelace for å få full oversikt over hvordan komponenten funker.

Feil / oppgaver / PR

Ingen som vi vet om. Hvis du finner noe muffens, registrer en feil under Issues i Github og merk den med nve-checkbox.

 

html
<nve-checkbox>Ja, jeg vil!</nve-checkbox>

Eksempler

Ledetekst

Teksten på høyre side kan legges inni nve-checkbox.

html
<nve-checkbox>Ledetekst</nve-checkbox>

Checked

checked er satt hvis boksen er krysset av og motsatt. Bruk indeterminate for å vise at man ikke har tatt stilling ennå.

html
<nve-checkbox checked>checked</nve-checkbox>
<nve-checkbox>unchecked</nve-checkbox>
<nve-checkbox indeterminate>indeterminate</nve-checkbox>

Disabled

Bruk disabled for å deaktivere boksen.

html
<nve-checkbox disabled>Disabled</nve-checkbox> <nve-checkbox>Enabled</nve-checkbox>

Spor

NavnBeskrivelse
(standard)The checkbox's label.
help-textText that describes how to use the checkbox. Alternatively, you can use the `help-text` attribute.

Hendelser

NavnArvet fraBeskrivelse
sl-blurSlCheckboxEmitted when the checkbox loses focus.
sl-changeSlCheckboxEmitted when the checked state changes.
sl-focusSlCheckboxEmitted when the checkbox gains focus.
sl-inputSlCheckboxEmitted when the checkbox receives input.
sl-invalidSlCheckboxEmitted when the form control has been checked for validity and its constraints aren't satisfied.

Egenskaper

NavnTypeArvet fraBeskrivelseReflected
inputHTMLInputElement SlCheckbox
titlestring = ''SlCheckbox
namestring = ''SlCheckboxThe name of the checkbox, submitted as a name/value pair with form data.
valuestring SlCheckboxThe current value of the checkbox, submitted as a name/value pair with form data.
size'small' | 'medium' | 'large' = 'medium'SlCheckboxThe checkbox's size.
disabledboolean = falseSlCheckboxDisables the checkbox.
checkedboolean = falseSlCheckboxDraws the checkbox in a checked state.
indeterminateboolean = falseSlCheckboxDraws the checkbox in an indeterminate state. This is usually applied to checkboxes that represents a "select all/none" behavior when associated checkboxes have a mix of checked and unchecked states.
defaultCheckedboolean = falseSlCheckboxThe default value of the form control. Primarily used for resetting the form control.
formstring = ''SlCheckboxBy default, form controls are associated with the nearest containing `<form>` element. This attribute allows you to place the form control outside of a form and associate it with the form that has this `id`. The form must be in the same document or shadow root for this to work.
requiredboolean = falseSlCheckboxMakes the checkbox a required field.
helpTextstring = ''SlCheckboxThe checkbox's help text. If you need to display HTML, use the `help-text` slot instead.
validity SlCheckboxGets the validity state object
validationMessage SlCheckboxGets the validation message

Metoder

NavnParametreReturtypeArvet fraBeskrivelse
handleDisabledChangeSlCheckbox
handleStateChangeSlCheckbox
clickSlCheckboxSimulates a click on the checkbox.
focus
options: FocusOptions
SlCheckboxSets focus on the checkbox.
blurSlCheckboxRemoves focus from the checkbox.
checkValiditySlCheckboxChecks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid.
getFormHTMLFormElement | nullSlCheckboxGets the associated form, if one exists.
reportValiditySlCheckboxChecks for validity and shows the browser's validation message if the control is invalid.
setCustomValidity
message: string
SlCheckboxSets a custom validation message. The value provided will be shown to the user when the form is submitted. To clear the custom validation message, call this method with an empty string.

Deler

NavnBeskrivelse
baseThe component's base wrapper.
controlThe square container that wraps the checkbox's checked state.
control--checkedMatches the control part when the checkbox is checked.
control--indeterminateMatches the control part when the checkbox is indeterminate.
checked-iconThe checked icon, an `<sl-icon>` element.
indeterminate-iconThe indeterminate icon, an `<sl-icon>` element.
labelThe container that wraps the checkbox's label.
form-control-help-textThe help text's wrapper.