Skip to content

@fabwcie/free-drawing / components/Modal

components/Modal ​

Classes ​

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:39

Dialog of the drawer (header with title and close button, body, footer), base of every dialog of the library. Added to the floating region of the layout, hidden until Modal.show: while shown, focus stays in it, Escape and a click outside close it (see options) and keys typed in it do not run drawer shortcuts.

Extended by

Constructors ​

Constructor ​

new Modal(drawer, options?): Modal

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:62

Create the dialog (hidden) in the floating region of the layout

Parameters
drawer ​

Drawer

Drawer the dialog belongs to (layout, texts, focus given back on hide)

options? ​

Partial<ModalOptions>

Options of the dialog, missing ones taken from defaultOptionsModal

Returns

Modal

Properties ​

$backdrop ​

$backdrop: HTMLDivElement

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:53

Backdrop around the dialog (only with backdrop option), shown and hidden with it

$modal: HTMLDivElement

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:41

Dialog element (role="dialog", aria-modal), holds header, body and footer

$modalBody ​

$modalBody: HTMLDivElement

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:45

Body of the dialog: content of the dialog

$modalFooter ​

$modalFooter: HTMLDivElement

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:47

Footer of the dialog: buttons of the dialog

$modalHeader ​

$modalHeader: HTMLDivElement

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:43

Header of the dialog: title and close button, removed when showHeader option is false

drawer ​

drawer: Drawer

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:51

Drawer the dialog belongs to

options ​

options: ModalOptions

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:49

Options of the dialog, merged with default ones

Methods ​

_createModal() ​

private _createModal(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:225

Creates dialog elements and adds them to the floating region of the layout (in a backdrop if enabled)

Returns

void

_getFocusables() ​

private _getFocusables(): HTMLElement[]

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:208

Elements of the dialog reached by Tab, in document order, as the browser does: enabled, shown, tab index not negative, one stop per radio group (its checked radio, else its first one)

Returns

HTMLElement[]

Buttons, links, fields and elements with a tab index of the dialog

_init() ​

private _init(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:76

Creates the dialog, its header (translated close button) unless showHeader is false, body and footer contents

Returns

void

_setupDefaultEvents() ​

private _setupDefaultEvents(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:117

Close button hides the dialog, keys typed in it do not reach the drawer

Returns

void

_trapFocus() ​

private _trapFocus(event): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:170

Tab and Shift+Tab cycle in modal

Parameters
event ​

KeyboardEvent

Keydown of Tab on the document, default prevented when focus wraps

Returns

void

appendBodyContent() ​

appendBodyContent(content): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:272

Adds text at the end of the body (as text, not parsed as HTML)

Parameters
content ​

string

Text added after the body content

Returns

void

destroy() ​

destroy(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:346

Hides the dialog and removes it from the page

Returns

void

hide() ​

hide(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:318

Hides the dialog and gives focus back to the element which opened it, else to the drawer, unless an element out of the drawer took it (field of the page or another drawer clicked)

Returns

void

isVisible() ​

isVisible(): boolean

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:339

Whether the dialog is shown

Returns

boolean

True while the dialog is shown

keepFocus() ​

protected keepFocus(...$preferred): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:195

Focus kept in the dialog when an update hid or disabled its focused element (its own button: start, stop...): on the first reachable of the given elements, else on the first element of the dialog, never on the page behind it

Parameters
$preferred ​

...HTMLElement[]

Elements to focus, in order of preference

Returns

void

setBodyContent() ​

setBodyContent(content): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:264

Replaces the body with an HTML string

Parameters
content ​

string

HTML markup of the body, empty to clear it

Returns

void

setFooterContent() ​

setFooterContent(content): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:280

Replaces the footer with an HTML string

Parameters
content ​

string

HTML markup of the footer (buttons), empty to clear it

Returns

void

setHeaderContent() ​

setHeaderContent(content): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:254

Replaces the header with an HTML string (an empty string keeps the current header)

Parameters
content ​

string

HTML markup of the header

Returns

void

setTitle() ​

setTitle(title): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:108

Title in header

Parameters
title ​

string

Text of the title (nothing without header)

Returns

void

show() ​

show(): void

Defined in: packages/free-drawing/src/components/Modal/Modal.ts:288

Shows the dialog and focuses its first focusable element. The element focused before is focused again on hide. While shown, Escape (closeOnEsc) and a click outside (closeOnClickOutside) hide it, Tab cycles in it.

Returns

void