Skip to content

@fabwcie/free-drawing / components/Dropdown

components/Dropdown ​

Classes ​

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:11

Disclosure menu: a button showing / hiding a menu below it, base of the settings menu. Escape and a click out of the button hide the menu (dropdown.hide event).

Extends

Extended by

Constructors ​

Constructor ​

new Dropdown(signal?): Dropdown

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:30

Create the button and the hidden menu holding an empty list, listen to clicks and Escape

Parameters
signal? ​

AbortSignal

Aborted when the listeners of the page are removed (signal of the drawer)

Returns

Dropdown

Overrides

default.constructor

Properties ​

_events ​

_events: Record<string, Listener[]> = {}

Defined in: packages/free-drawing/src/utils/MicroEvent.ts:44

Listeners by event name, in order of registration

Inherited from

default._events

$button ​

$button: HTMLButtonElement

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:15

Button showing / hiding the menu (aria-expanded)

$dropdownContainer: HTMLDivElement

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:13

Element holding the button and the menu, to add to the page

$dropdownItem: HTMLLIElement

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:21

List item element with the item class, created for subclasses (not added to the list)

$dropdownList: HTMLUListElement

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:19

List of the menu, its default content

$menu: HTMLDivElement

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:17

Menu shown below the button, holds the content

Methods ​

_initEvents() ​

private _initEvents(): void

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:105

Button toggles the menu, Escape hides it (focus back on button), a click out of the button hides it

Returns

void

_setShown() ​

private _setShown(shown): void

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:95

Shows or hides the menu and updates aria-expanded of the button, without event

Parameters
shown ​

boolean

True to show the menu, false to hide it

Returns

void

hide() ​

hide(): void

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:77

Hides the menu and triggers dropdown.hide

Returns

void

isShown() ​

isShown(): boolean

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:87

Whether the menu is shown

Returns

boolean

True while the menu is shown

off() ​

off<K>(events?, fct?): void

Defined in: packages/free-drawing/src/utils/MicroEvent.ts:71

Remove a listener of an event: without listener all listeners of this event, without arguments all listeners

Type Parameters
K ​

K extends EventName<DropdownEventMap>

name of the event

Parameters
events? ​

K

event name (several separated by spaces in JavaScript)

fct? ​

EmitterListener<DropdownEventMap, K>

listener given to on

Returns

void

Inherited from

default.off

on() ​

on<K>(events, fct): void

Defined in: packages/free-drawing/src/utils/MicroEvent.ts:57

Listen to an event

Type Parameters
K ​

K extends EventName<DropdownEventMap>

name of the event

Parameters
events ​

K

event name (several separated by spaces in JavaScript)

fct ​

EmitterListener<DropdownEventMap, K>

listener, called on each trigger with the arguments of the event

Returns

void

Inherited from

default.on

setContent() ​

setContent(content): void

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:59

Sets the content of the menu: an HTML string replaces it, a node is added at its end

Parameters
content ​

string | Node

HTML markup replacing the content, or node added after it

Returns

void

show() ​

show(): void

Defined in: packages/free-drawing/src/components/Dropdown/Dropdown.ts:70

Shows the menu

Returns

void

trigger() ​

trigger<K>(events, ...args): void

Defined in: packages/free-drawing/src/utils/MicroEvent.ts:100

Call listeners of an event, in order of registration. A listener may add or remove listeners: the ones added are called from the next trigger, the ones removed (not called yet) are not called, the others are all called.

Type Parameters
K ​

K extends EventName<DropdownEventMap>

name of the event

Parameters
events ​

K

event name (several separated by spaces in JavaScript)

args ​

...EventArgs<DropdownEventMap, K>

arguments given to listeners, as typed by the event

Returns

void

Inherited from

default.trigger