Bootstrap

API modal

createModal

function

createModal<Data>(config?): ModalWidget<Data>

Creates a new modal widget instance.

Type Parameters

Data

Parameters

config?: PropsConfig<ModalProps<Data>>

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

Returns

ModalWidget<Data>

a new modal widget instance


getModalDefaultConfig

function

getModalDefaultConfig(): ModalProps<any>

Retrieve a shallow copy of the default modal config

Returns

ModalProps<any>

the default modal config


ModalActions

interface
Methods
closeButtonClick

closeButtonClick(event): void

Action to be called when the user clicks on the close button. It closes the modal with the modalCloseButtonClick result.

Parameters

event: Pick<MouseEvent, never>

mouse event

Returns

void


modalClick

modalClick(event): void

Action to be called when the user clicks on the modal DOM element (which is supposed to have the size of the full viewport). If the click is not done on a descendant of the modal DOM element, it is considered to be done outside the modal and, depending on the value of the closeOnOutsideClick prop, the modal is or isn't closed (with the modalOutsideClick result).

Parameters

event: Pick<MouseEvent, "currentTarget" | "target">

mouse event

Returns

void


ModalApi

interface
Type Parameters

Data

Properties
patch

patch: (parameters) => void

Modify the parameter values, and recalculate the stores accordingly

Parameters

parameters: Partial<ModalProps<Data>>

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
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: typeof modalCloseButtonClick

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.


ModalContext

type alias

ModalContext<Data>: WidgetSlotContext<ModalWidget<Data>>

Type Parameters

Data


ModalDirectives

interface
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: typeof modalOutsideClick

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
Type Parameters

Data

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

fadeTransition


children

children: SlotContent<ModalContext<Data>>

Body of the modal.


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

contentData

contentData: Data

Data to use in content slots


footer: SlotContent<ModalContext<Data>>

Footer of the modal.


fullscreen

fullscreen: boolean

Option to create a fullscreen modal, according to the bootstrap documentation.

Default Value

false


header

header: SlotContent<ModalContext<Data>>

Header of the modal. The default header includes title.


modalTransition

modalTransition: TransitionFn

The transition to use for the modal.

Default Value

fadeTransition


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
() => {}

structure

structure: SlotContent<ModalContext<Data>>

Structure of the modal. The default structure uses header, children and footer.


title

title: SlotContent<ModalContext<Data>>

Title of the modal.


visible

visible: boolean

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

Default Value

false


ModalSlots

interface
Properties
default

default: ModalContext<any>


footer: ModalContext<any>


header

header: ModalContext<any>


structure

structure: ModalContext<any>


title

title: ModalContext<any>


ModalState

interface
Type Parameters

Data

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.


children

children: SlotContent<ModalContext<Data>>

Body of the modal.


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

contentData

contentData: Data

Data to use in content slots


footer: SlotContent<ModalContext<Data>>

Footer of the modal.


fullscreen

fullscreen: boolean

Option to create a fullscreen modal, according to the bootstrap documentation.

Default Value

false


header

header: SlotContent<ModalContext<Data>>

Header of the modal. The default header includes title.


hidden

hidden: boolean

Whether the modal is fully hidden.


modalElement

modalElement: null | HTMLElement

DOM element of the modal.


structure

structure: SlotContent<ModalContext<Data>>

Structure of the modal. The default structure uses header, children and footer.


title

title: SlotContent<ModalContext<Data>>

Title 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<Data>: Widget<ModalProps<Data>, ModalState<Data>, ModalApi<Data>, ModalActions, ModalDirectives>

Type Parameters

Data


openModal

function

openModal<Data>(options, __namedParameters): Promise<any>

Type Parameters

Data

Parameters

options: Partial<ModalProps<Data>>

__namedParameters = {}

__namedParameters.context?: Map<any, any>

Returns

Promise<any>