headless

API modal

createModal

function

createModal(config$?): ModalWidget

Creates a new modal widget instance.

Parameters

config$?: PropsConfig<ModalProps>

config of the modal, either as a store or as an object containing values or stores.

Returns

ModalWidget

a new modal widget instance


getModalDefaultConfig

function

getModalDefaultConfig(): ModalProps

Returns a copy of the default modal config.

Returns

ModalProps

a copy of the default modal config


ModalApi

interface

API of the modal widget.

Properties
patch

patch: (parameters) => void

Method to change some modal properties.

Modify the parameter values, and recalculate the stores accordingly

Parameters

parameters: Partial<ModalProps>

Returns

void

Methods
close

close(result?): void

Closes the modal with the given result.

Parameters

result?: any

result of the modal, as passed in the result property of the event passed to the onBeforeClose event handler (and possibly changed by it) and resolved by the promise returned by the open method.

Returns

void


open

open(): Promise<any>

Opens the modal and returns a promise that is resolved when the modal is closed. The resolved value is the result passed to the close method and possibly changed by the onBeforeClose event handler

Returns

Promise<any>


ModalBeforeCloseEvent

interface

Type of the parameter of onBeforeClose.

Properties
cancel

cancel: boolean

Whether to cancel the close of the modal. It can be changed from the onBeforeClose event handler.


result

result: any

Result of the modal, which is the value passed to the close method and later resolved by the promise returned by the open method. If needed, it can be changed from the onBeforeClose event handler.


modalCloseButtonClick

constant

const modalCloseButtonClick: unique symbol

Value present in the result property of the onBeforeClose event and returned by the open method, when the modal is closed by a click on the close button.


ModalDirectives

interface

Directives of the modal widget.

Properties
backdropDirective

backdropDirective: Directive

Directive to put on the backdrop DOM element.


backdropPortalDirective

backdropPortalDirective: Directive

Portal directive to put on the backdrop DOM element.


closeButtonDirective

closeButtonDirective: Directive

Directive that adds all the necessary attributes to the close button


dialogDirective

dialogDirective: Directive

Directive to apply to the dialog element when using the native HTMLDialogElement


modalDirective

modalDirective: Directive

Directive to put on the modal DOM element.


modalPortalDirective

modalPortalDirective: Directive

Portal directive to put on the modal DOM element.


modalOutsideClick

constant

const modalOutsideClick: unique symbol

Value present in the result property of the onBeforeClose event and returned by the open method, when the modal is closed by a click inside the viewport but outside the modal.


ModalProps

interface

Properties of the modal widget.

Properties
animated

animated: boolean

Whether the modal and its backdrop (if present) should be animated when shown or hidden.

Default Value

true


ariaCloseButtonLabel

ariaCloseButtonLabel: string

Value of the aria-label attribute to put on the close button.

Default Value

'Close'


backdrop

backdrop: boolean

Whether a backdrop should be created behind the modal.

Default Value

true


backdropClass

backdropClass: string

Classes to add on the backdrop DOM element.

Default Value

''


backdropTransition

backdropTransition: TransitionFn

The transition to use for the backdrop behind the modal (if present).

Default Value
async () => {}

className

className: string

CSS classes to be applied on the widget main container

Default Value

''


closeButton

closeButton: boolean

Whether to display the close button.

Default Value

true


closeOnOutsideClick

closeOnOutsideClick: boolean

Whether the modal should be closed when clicking on the viewport outside the modal.

Default Value

true


container

container: null | HTMLElement

Which element should contain the modal and backdrop DOM elements. If it is not null, the modal and backdrop DOM elements are moved to the specified container. Otherwise, they stay where the widget is located.

Default Value
typeof window !== 'undefined' ? document.body : null

modalTransition

modalTransition: TransitionFn

The transition to use for the modal.

Default Value
async () => {}

onBeforeClose

onBeforeClose: (event) => void

Event to be triggered when the modal is about to be closed (i.e. the close method was called).

Parameters

event: ModalBeforeCloseEvent

event giving access to the argument given to the close method and allowing to cancel the close process.

Returns

void

Default Value
() => {}

onHidden

onHidden: () => void

Event to be triggered when the transition is completed and the modal is not visible.

Returns

void

Default Value
() => {}

onShown

onShown: () => void

Event to be triggered when the transition is completed and the modal is visible.

Returns

void

Default Value
() => {}

onVisibleChange

onVisibleChange: (visible) => void

Event to be triggered when the visible property changes.

Parameters

visible: boolean

new value of the visible propery

Returns

void

Default Value
() => {}

visible

visible: boolean

Whether the modal should be visible when the transition is completed.

Default Value

false


ModalState

interface

State of the modal widget.

Properties
ariaCloseButtonLabel

ariaCloseButtonLabel: string

Value of the aria-label attribute to put on the close button.

Default Value

'Close'


backdropClass

backdropClass: string

Classes to add on the backdrop DOM element.

Default Value

''


backdropHidden

backdropHidden: boolean

Whether the backdrop is fully hidden. This can be true either because backdrop is false or because visible is false and there is no current transition.


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


closeButton

closeButton: boolean

Whether to display the close button.

Default Value

true


container

container: null | HTMLElement

Which element should contain the modal and backdrop DOM elements. If it is not null, the modal and backdrop DOM elements are moved to the specified container. Otherwise, they stay where the widget is located.

Default Value
typeof window !== 'undefined' ? document.body : null

hidden

hidden: boolean

Whether the modal is fully hidden.


modalElement

modalElement: null | HTMLElement

DOM element of the modal.


transitioning

transitioning: boolean

Whether there is an active transition to either display or hide the modal.


visible

visible: boolean

Whether the modal should be visible when the transition is completed.

Default Value

false


ModalWidget

type alias

ModalWidget: Widget<ModalProps, ModalState, ModalApi, ModalDirectives>

Modal widget.