Disclosure
Om komponenten
En Disclosure kan ekspandere og kollapse relatert innhold. Den består i hovedsak av en knapp og et panel. Knappen styrer om innholdet i panelet vises eller skjules.
Den fungerer på lik måte som <details> og <summary> i HTML, men de elementene kan ofte være litt vanskelig å tilpasse utseendet på.
Egnet til:
- Når det er behov for å vise tilleggsvalg på en strukturert måte, som for eksempel i et filter.
- Disclosure brukes ofte til "Les mer" i komponenter
Den skiller seg fra Accordion ved at:
- Disclosure er som regel frittstående, og må ikke være en del av en gruppe.
- Teksten på knappen er ikke implisitt en heading.
- Innholdet i panelet er ikke nødvendigvis en egen section/group. Det er som regel en kortere tekst, eller noe interaktivt.

Varianter
Et vanlig bruksområde for Disclosure er "Les mer"
<UNSAFE_Disclosure defaultExpanded> <UNSAFE_DisclosureButton className="description" withChevron> Les mer </UNSAFE_DisclosureButton> <UNSAFE_DisclosurePanel> <p> For å komme raskere i gang med å ta i bruk Obos-banken så kan du nå på forhånd velge hvilke type kontoer du ønsker å starte med.. </p> </UNSAFE_DisclosurePanel> </UNSAFE_Disclosure>
For å lettere kunne bruke komponenten frem til den er stabil, kan det være lurt å rename i importen:
import { UNSAFE_Disclosure as Disclosure, UNSAFE_DisclosureButton as DisclosureButton, UNSAFE_DisclosureGroup as DisclosureGroup, UNSAFE_DisclosurePanel as DisclosurePanel, } from './disclosure';
Bruk med "fieldsets"
For å være tilgjengelig har DisclosurePanel
automatisk satt en aria rolle. Dersom Disclosure
skal benyttes sammen med for eksempel CheckboxGroup, RadioGroup eller andre fieldsets, er det viktig å overstyre denne rollen og knytte fieldsettet til DisclosureButton
ved hjelp av aria-labelledby
.
<UNSAFE_Disclosure> <UNSAFE_DisclosureButton id="my-id" withChevron> Kjøpsalternativer </UNSAFE_DisclosureButton> <UNSAFE_DisclosurePanel role="none"> <CheckboxGroup aria-labelledby="my-id"> <Checkbox value="deleie">Deleie</Checkbox> <Checkbox value="bostart">Bostart</Checkbox> <Checkbox value="boligbytte">Boligbytte</Checkbox> </CheckboxGroup> </UNSAFE_DisclosurePanel> </UNSAFE_Disclosure>
DisclosureGroup
En DisclosureGroup
kan benyttes til å gruppere sammen relaterte disclosures. Den støtter at det kun kan være en utvidet Disclosure av gangen, eller opp til flere.
Grunnmuren re-eksporterer React Aria sin DisclosureGroup, så se mer utfyllende dokumentasjon og eksempler på bruk av komponenten der.
<UNSAFE_DisclosureGroup> <UNSAFE_Disclosure> <UNSAFE_DisclosureButton withChevron>Personlig informasjon</UNSAFE_DisclosureButton> <UNSAFE_DisclosurePanel>Personlig informasjon her</UNSAFE_DisclosurePanel> </UNSAFE_Disclosure> <UNSAFE_Disclosure> <UNSAFE_DisclosureButton withChevron>Adresse</UNSAFE_DisclosureButton> <UNSAFE_DisclosurePanel>Adresse her</UNSAFE_DisclosurePanel> </UNSAFE_Disclosure> </UNSAFE_DisclosureGroup>
Props
Disclosure
Prop | Description | Default |
---|---|---|
id? | An id for the disclosure when used within a DisclosureGroup, matching the id used in `expandedKeys`. | - |
isDisabled? | Whether the disclosure is disabled. | - |
onExpandedChange? | Handler that is called when the disclosure's expanded state changes. | - |
isExpanded? | Whether the disclosure is expanded (controlled). | - |
defaultExpanded? | Whether the disclosure is expanded by default (uncontrolled). | - |
children? | The children of the component. A function may be provided to alter the children based on component state. | - |
className? | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. | - |
style? | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. | - |
slot? | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. | - |
ref? | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} | - |
key? | - |
DisclosureButton
Prop | Description | Default |
---|---|---|
className? | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. | - |
style? | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. | - |
isPending? | Whether the button is in a pending state. This disables press and hover events while retaining focusability, and announces the pending state to screen readers. | - |
isDisabled? | Whether the button is disabled. | - |
onPress? | Handler that is called when the press is released over the target. | - |
onPressStart? | Handler that is called when a press interaction starts. | - |
onPressEnd? | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | - |
onPressChange? | Handler that is called when the press state changes. | - |
onPressUp? | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | - |
autoFocus? | Whether the element should receive focus on render. | - |
onFocus? | Handler that is called when the element receives focus. | - |
onBlur? | Handler that is called when the element loses focus. | - |
onFocusChange? | Handler that is called when the element's focus status changes. | - |
onKeyDown? | Handler that is called when a key is pressed. | - |
onKeyUp? | Handler that is called when a key is released. | - |
aria-haspopup? | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | - |
aria-pressed? | Indicates the current "pressed" state of toggle buttons. | - |
aria-current? | Indicates whether this element represents the current item within a container or set of related elements. | - |
type? | The behavior of the button when used in an HTML form. | 'button' |
preventFocusOnPress? | Whether to prevent focus from moving to the button when pressing it. Caution, this can make the button inaccessible and should only be used when alternative keyboard interaction is provided, such as ComboBox's MenuTrigger or a NumberField's increment/decrement control. | - |
excludeFromTabOrder? | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. | - |
id? | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). | - |
aria-label? | Defines a string value that labels the current element. | - |
aria-labelledby? | Identifies the element (or elements) that labels the current element. | - |
aria-describedby? | Identifies the element (or elements) that describes the object. | - |
aria-details? | Identifies the element (or elements) that provide a detailed, extended description for the object. | - |
form? | The `<form>` element to associate the button with. The value of this attribute must be the id of a `<form>` in the same document. | - |
formAction? | The URL that processes the information submitted by the button. Overrides the action attribute of the button's form owner. | - |
formEncType? | Indicates how to encode the form data that is submitted. | - |
formMethod? | Indicates the HTTP method used to submit the form. | - |
formNoValidate? | Indicates that the form is not to be validated when it is submitted. | - |
formTarget? | Overrides the target attribute of the button's form owner. | - |
name? | Submitted as a pair with the button's value as part of the form data. | - |
value? | The value associated with the button's name when it's submitted with the form data. | - |
onHoverStart? | Handler that is called when a hover interaction starts. | - |
onHoverEnd? | Handler that is called when a hover interaction ends. | - |
onHoverChange? | Handler that is called when the hover state changes. | - |
slot? | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. | - |
isIconOnly? | When the button is without text, but with a single icon. | false |
withChevron? | - | |
ref? | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} | - |
key? | - |
DisclosurePanel
Prop | Description | Default |
---|---|---|
className? | - | |
style? | - | |
color? | - | |
rel? | - | |
autoFocus? | - | |
onFocus? | - | |
onBlur? | - | |
onKeyDown? | - | |
onKeyUp? | - | |
aria-expanded? | Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed. | - |
aria-haspopup? | Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element. | - |
aria-controls? | Identifies the element (or elements) whose contents or presence are controlled by the current element. @see aria-owns. | - |
aria-pressed? | Indicates the current "pressed" state of toggle buttons. @see aria-checked @see aria-selected. | - |
aria-current? | Indicates the element that represents the current item within a container or set of related elements. | - |
id? | - | |
aria-label? | Defines a string value that labels the current element. @see aria-labelledby. | - |
aria-labelledby? | Identifies the element (or elements) that labels the current element. @see aria-describedby. | - |
aria-describedby? | Identifies the element (or elements) that describes the object. @see aria-labelledby | - |
aria-details? | Identifies the element that provides a detailed, extended description for the object. @see aria-describedby. | - |
slot? | - | |
hidden? | - | |
content? | - | |
onChange? | - | |
aria-errormessage? | Identifies the element that provides an error message for the object. @see aria-invalid @see aria-describedby. | - |
defaultValue? | - | |
title? | - | |
aria-activedescendant? | Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application. | - |
aria-autocomplete? | Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made. | - |
enterKeyHint? | - | |
inputMode? | Hints at the type of data that might be entered by the user while editing the element or its contents @see {@link https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute} | - |
autoCorrect? | - | |
spellCheck? | - | |
onCopy? | - | |
onCut? | - | |
onPaste? | - | |
onCompositionStart? | - | |
onCompositionEnd? | - | |
onCompositionUpdate? | - | |
onSelect? | - | |
onBeforeInput? | - | |
onInput? | - | |
defaultChecked? | - | |
suppressContentEditableWarning? | - | |
suppressHydrationWarning? | - | |
accessKey? | - | |
autoCapitalize? | - | |
contentEditable? | - | |
contextMenu? | - | |
dir? | - | |
draggable? | - | |
lang? | - | |
nonce? | - | |
tabIndex? | - | |
translate? | - | |
radioGroup? | - | |
about? | - | |
datatype? | - | |
inlist? | - | |
prefix? | - | |
property? | - | |
resource? | - | |
rev? | - | |
typeof? | - | |
vocab? | - | |
autoSave? | - | |
itemProp? | - | |
itemScope? | - | |
itemType? | - | |
itemID? | - | |
itemRef? | - | |
results? | - | |
security? | - | |
unselectable? | - | |
popover? | - | |
popoverTargetAction? | - | |
popoverTarget? | - | |
inert? | @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert | - |
is? | Specify that a standard HTML element should behave like a defined custom built-in element @see {@link https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is} | - |
exportparts? | @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/exportparts} | - |
part? | @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/part} | - |
aria-atomic? | Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute. | - |
aria-braillelabel? | Defines a string value that labels the current element, which is intended to be converted into Braille. @see aria-label. | - |
aria-brailleroledescription? | Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. @see aria-roledescription. | - |
aria-busy? | - | |
aria-checked? | Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. @see aria-pressed @see aria-selected. | - |
aria-colcount? | Defines the total number of columns in a table, grid, or treegrid. @see aria-colindex. | - |
aria-colindex? | Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. @see aria-colcount @see aria-colspan. | - |
aria-colindextext? | Defines a human readable text alternative of aria-colindex. @see aria-rowindextext. | - |
aria-colspan? | Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. @see aria-colindex @see aria-rowspan. | - |
aria-description? | Defines a string value that describes or annotates the current element. @see related aria-describedby. | - |
aria-disabled? | Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. @see aria-hidden @see aria-readonly. | - |
aria-dropeffect? | Indicates what functions can be performed when a dragged object is released on the drop target. @deprecated in ARIA 1.1 | - |
aria-flowto? | Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order. | - |
aria-grabbed? | Indicates an element's "grabbed" state in a drag-and-drop operation. @deprecated in ARIA 1.1 | - |
aria-hidden? | Indicates whether the element is exposed to an accessibility API. @see aria-disabled. | - |
aria-invalid? | Indicates the entered value does not conform to the format expected by the application. @see aria-errormessage. | - |
aria-keyshortcuts? | Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element. | - |
aria-level? | Defines the hierarchical level of an element within a structure. | - |
aria-live? | Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region. | - |
aria-modal? | Indicates whether an element is modal when displayed. | - |
aria-multiline? | Indicates whether a text box accepts multiple lines of input or only a single line. | - |
aria-multiselectable? | Indicates that the user may select more than one item from the current selectable descendants. | - |
aria-orientation? | Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous. | - |
aria-owns? | Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. @see aria-controls. | - |
aria-placeholder? | Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format. | - |
aria-posinset? | Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. @see aria-setsize. | - |
aria-readonly? | Indicates that the element is not editable, but is otherwise operable. @see aria-disabled. | - |
aria-relevant? | Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. @see aria-atomic. | - |
aria-required? | Indicates that user input is required on the element before a form may be submitted. | - |
aria-roledescription? | Defines a human-readable, author-localized description for the role of an element. | - |
aria-rowcount? | Defines the total number of rows in a table, grid, or treegrid. @see aria-rowindex. | - |
aria-rowindex? | Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. @see aria-rowcount @see aria-rowspan. | - |
aria-rowindextext? | Defines a human readable text alternative of aria-rowindex. @see aria-colindextext. | - |
aria-rowspan? | Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. @see aria-rowindex @see aria-colspan. | - |
aria-selected? | Indicates the current "selected" state of various widgets. @see aria-checked @see aria-pressed. | - |
aria-setsize? | Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. @see aria-posinset. | - |
aria-sort? | Indicates if items in a table or grid are sorted in ascending or descending order. | - |
aria-valuemax? | Defines the maximum allowed value for a range widget. | - |
aria-valuemin? | Defines the minimum allowed value for a range widget. | - |
aria-valuenow? | Defines the current value for a range widget. @see aria-valuetext. | - |
aria-valuetext? | Defines the human readable text alternative of aria-valuenow for a range widget. | - |
dangerouslySetInnerHTML? | - | |
onCopyCapture? | - | |
onCutCapture? | - | |
onPasteCapture? | - | |
onCompositionEndCapture? | - | |
onCompositionStartCapture? | - | |
onCompositionUpdateCapture? | - | |
onFocusCapture? | - | |
onBlurCapture? | - | |
onChangeCapture? | - | |
onBeforeInputCapture? | - | |
onInputCapture? | - | |
onReset? | - | |
onResetCapture? | - | |
onSubmit? | - | |
onSubmitCapture? | - | |
onInvalid? | - | |
onInvalidCapture? | - | |
onLoad? | - | |
onLoadCapture? | - | |
onError? | - | |
onErrorCapture? | - | |
onKeyDownCapture? | - | |
onKeyPress? | @deprecated Use `onKeyUp` or `onKeyDown` instead | - |
onKeyPressCapture? | @deprecated Use `onKeyUpCapture` or `onKeyDownCapture` instead | - |
onKeyUpCapture? | - | |
onAbort? | - | |
onAbortCapture? | - | |
onCanPlay? | - | |
onCanPlayCapture? | - | |
onCanPlayThrough? | - | |
onCanPlayThroughCapture? | - | |
onDurationChange? | - | |
onDurationChangeCapture? | - | |
onEmptied? | - | |
onEmptiedCapture? | - | |
onEncrypted? | - | |
onEncryptedCapture? | - | |
onEnded? | - | |
onEndedCapture? | - | |
onLoadedData? | - | |
onLoadedDataCapture? | - | |
onLoadedMetadata? | - | |
onLoadedMetadataCapture? | - | |
onLoadStart? | - | |
onLoadStartCapture? | - | |
onPause? | - | |
onPauseCapture? | - | |
onPlay? | - | |
onPlayCapture? | - | |
onPlaying? | - | |
onPlayingCapture? | - | |
onProgress? | - | |
onProgressCapture? | - | |
onRateChange? | - | |
onRateChangeCapture? | - | |
onResize? | - | |
onResizeCapture? | - | |
onSeeked? | - | |
onSeekedCapture? | - | |
onSeeking? | - | |
onSeekingCapture? | - | |
onStalled? | - | |
onStalledCapture? | - | |
onSuspend? | - | |
onSuspendCapture? | - | |
onTimeUpdate? | - | |
onTimeUpdateCapture? | - | |
onVolumeChange? | - | |
onVolumeChangeCapture? | - | |
onWaiting? | - | |
onWaitingCapture? | - | |
onAuxClick? | - | |
onAuxClickCapture? | - | |
onClick? | - | |
onClickCapture? | - | |
onContextMenu? | - | |
onContextMenuCapture? | - | |
onDoubleClick? | - | |
onDoubleClickCapture? | - | |
onDrag? | - | |
onDragCapture? | - | |
onDragEnd? | - | |
onDragEndCapture? | - | |
onDragEnter? | - | |
onDragEnterCapture? | - | |
onDragExit? | - | |
onDragExitCapture? | - | |
onDragLeave? | - | |
onDragLeaveCapture? | - | |
onDragOver? | - | |
onDragOverCapture? | - | |
onDragStart? | - | |
onDragStartCapture? | - | |
onDrop? | - | |
onDropCapture? | - | |
onMouseDown? | - | |
onMouseDownCapture? | - | |
onMouseEnter? | - | |
onMouseLeave? | - | |
onMouseMove? | - | |
onMouseMoveCapture? | - | |
onMouseOut? | - | |
onMouseOutCapture? | - | |
onMouseOver? | - | |
onMouseOverCapture? | - | |
onMouseUp? | - | |
onMouseUpCapture? | - | |
onSelectCapture? | - | |
onTouchCancel? | - | |
onTouchCancelCapture? | - | |
onTouchEnd? | - | |
onTouchEndCapture? | - | |
onTouchMove? | - | |
onTouchMoveCapture? | - | |
onTouchStart? | - | |
onTouchStartCapture? | - | |
onPointerDown? | - | |
onPointerDownCapture? | - | |
onPointerMove? | - | |
onPointerMoveCapture? | - | |
onPointerUp? | - | |
onPointerUpCapture? | - | |
onPointerCancel? | - | |
onPointerCancelCapture? | - | |
onPointerEnter? | - | |
onPointerLeave? | - | |
onPointerOver? | - | |
onPointerOverCapture? | - | |
onPointerOut? | - | |
onPointerOutCapture? | - | |
onGotPointerCapture? | - | |
onGotPointerCaptureCapture? | - | |
onLostPointerCapture? | - | |
onLostPointerCaptureCapture? | - | |
onScroll? | - | |
onScrollCapture? | - | |
onScrollEnd? | - | |
onScrollEndCapture? | - | |
onWheel? | - | |
onWheelCapture? | - | |
onAnimationStart? | - | |
onAnimationStartCapture? | - | |
onAnimationEnd? | - | |
onAnimationEndCapture? | - | |
onAnimationIteration? | - | |
onAnimationIterationCapture? | - | |
onToggle? | - | |
onBeforeToggle? | - | |
onTransitionCancel? | - | |
onTransitionCancelCapture? | - | |
onTransitionEnd? | - | |
onTransitionEndCapture? | - | |
onTransitionRun? | - | |
onTransitionRunCapture? | - | |
onTransitionStart? | - | |
onTransitionStartCapture? | - | |
role? | - | |
ref? | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs} | - |
key? | - |
DisclosureGroup
Prop | Description | Default |
---|---|---|
allowsMultipleExpanded? | Whether multiple items can be expanded at the same time. | - |
isDisabled? | Whether all items are disabled. | - |
expandedKeys? | The currently expanded keys in the group (controlled). | - |
defaultExpandedKeys? | The initial expanded keys in the group (uncontrolled). | - |
onExpandedChange? | Handler that is called when items are expanded or collapsed. | - |
children? | The children of the component. A function may be provided to alter the children based on component state. | - |
className? | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. | - |
style? | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. | - |
id? | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). | - |