@fabwcie/free-drawing / utils/dom
utils/dom
Functions
arrowNavigation()
arrowNavigation(
$container,getItems,orientation,onMove?):void
Defined in: packages/free-drawing/src/utils/dom.ts:171
Arrow keys move focus between items (last to first and back), Home / End to first / last item. Handled keys and arrows of the other orientation are not propagated, so drawer shortcuts (e.g. arrows moving selection) are not triggered from an item.
Parameters
$container
HTMLElement
element listening to keydown of its items
getItems
() => HTMLElement[]
items in navigation order, read on each key (disabled buttons skipped)
orientation
"horizontal" | "vertical"
horizontal: left / right arrows, vertical: up / down arrows
onMove?
($item) => void
called with the newly focused item
Returns
void
createButton()
createButton(...
classNames):HTMLButtonElement
Defined in: packages/free-drawing/src/utils/dom.ts:56
Button with given classes, type="button": default type submit would submit a form of the page
Parameters
classNames
...string[]
CSS classes of the button
Returns
HTMLButtonElement
new button, not added to the page
createSwitch()
createSwitch(
checked?):HTMLInputElement
Defined in: packages/free-drawing/src/utils/dom.ts:70
On / off switch: checkbox announced as a switch (state read as on / off), keyboard (Space) and pointer as a checkbox
Parameters
checked?
boolean = false
initial state, on when true
Returns
HTMLInputElement
new checkbox with role switch, not added to the page
disableElement()
disableElement(
$el):void
Defined in: packages/free-drawing/src/utils/dom.ts:9
Disable an element: aria-disabled and disabled class, disabled property of buttons. Focused (by its own action: undo at the end of history, next slide at the last one...), the focus stays in the drawer: the browser would give it to the page (not in a modal dialog: it keeps its focus)
Parameters
$el
HTMLElement
button, menu item or other element to disable
Returns
void
enableElement()
enableElement(
$el):void
Defined in: packages/free-drawing/src/utils/dom.ts:42
Enable an element disabled by disableElement
Parameters
$el
HTMLElement
element to enable
Returns
void
fitHeight()
fitHeight(
$el):void
Defined in: packages/free-drawing/src/utils/dom.ts:141
Menu or panel shown below its button kept in the drawer and the window (small screens): its height is limited to the space below it, the rest scrolls
Parameters
$el
HTMLElement
Element shown (its top is read)
Returns
void
hasFocusOutside()
hasFocusOutside(
$container):boolean
Defined in: packages/free-drawing/src/utils/dom.ts:156
Focus taken by an element out of the container (field of the page, another drawer), e.g. by the click hiding a menu or a dialog: a component hidden then gives focus back to the drawer only without it
Parameters
$container
HTMLElement
Container of the component (drawer)
Returns
boolean
True when an element out of the container has focus (not the body: focus lost)
isComposing()
isComposing(
e):boolean
Defined in: packages/free-drawing/src/utils/dom.ts:129
Key pressed while a text is composed with an input method (Chinese, Japanese, Korean...): its Enter or Escape ends the composition, it does not validate nor close the field (Safari ends it with a key of code 229, not composing)
Parameters
e
KeyboardEvent
Key pressed in a field
Returns
boolean
True when the key belongs to a composition
isUnreachable()
isUnreachable(
$el):boolean
Defined in: packages/free-drawing/src/utils/dom.ts:28
Element the focus can't stay on: removed, hidden (also by a parent, or by zen mode) or disabled
Parameters
$el
Element
Element focused before a change (button hidden by its own action...)
Returns
boolean
true when the focus has to go elsewhere
placeInView()
placeInView(
drawer,$el,left,top):void
Defined in: packages/free-drawing/src/utils/dom.ts:214
Element placed in view: absolute position in the drawer container (floating region) from view coordinates
Parameters
drawer
drawer holding the element
$el
HTMLElement
element of the floating region
left
number
left of the element in view (px)
top
number
top of the element in view (px)
Returns
void
replaceUrl()
replaceUrl(
url):void
Defined in: packages/free-drawing/src/utils/dom.ts:97
Address of the page replaced (room joined, link opened or left), state of its history kept: the router of the host app (React Router, Next.js...) keeps its own there
Parameters
url
string
New address of the page
Returns
void
setLabel()
setLabel(
$el,label):void
Defined in: packages/free-drawing/src/utils/dom.ts:106
Accessible name of an element (icon button...), also shown as tooltip
Parameters
$el
HTMLElement
element to name
label
string
translated name, set as aria-label and title
Returns
void
setPressed()
setPressed(
$el,pressed):void
Defined in: packages/free-drawing/src/utils/dom.ts:116
Toggle button state: active class and aria-pressed (aria-checked for menu items)
Parameters
$el
HTMLElement
toggle button or menuitemcheckbox item
pressed
boolean
true when on
Returns
void
uniqueId()
uniqueId(
prefix):string
Defined in: packages/free-drawing/src/utils/dom.ts:88
Unique element id, for aria references (aria-labelledby, aria-controls...)
Parameters
prefix
string
kind of element, put in the id
Returns
string
drawer-<prefix>-<number> id, unique in the page