9.0.18 • Published 11 months ago

@workday/canvas-kit-popup-stack v9.0.18

Weekly downloads
918
License
Apache-2.0
Repository
github
Last release
11 months ago

Canvas Kit Popup Stack

Stack for managing popup UIs to coordinate global concerns like escape key handling and rendering order. The popup stack is a FILO stack that is framework agnostic and is shared for the entire page. This sharing is enforced. If the window stack variable (window.workday.__popupStack) has already been declared, the first-instantiated instance will be used. There is no need to worry about bootstrapping at a specific time.

What is Stacked UI?

A Stacked UI (typically classified as "popups") component generally isn't statically positioned (not in the normal flow of the page) and sits on top of other content - usually occluding other content. A stacked UI element typically redirects a users attention temporarily. For example, a Modal appears on top of all other content while it is active. A tooltip appears on top of other content when the target is focused or hovered.

Stacked components include:

  • Tooltips
  • Modal dialogs
  • Select menu dropdown
  • Toast messages
  • Popups
  • Snackbars
  • Dropdown menus
  • Windows

Stacked UI components are usually unbounded by the physical boundaries of a target element through a technique of "portalling" the Popup to the bottommost element of the body element. This allows a Tooltip to appear outside any overflowed content. This technique does not work outside the confines of an iframe, however.

Why do I need a stack manager?

Simple UIs may define z-index values globally per component type, so why do we need to manage popups? Popups usually have accessibility requirements that the popup should close if the escape key is pressed. The naive way of doing this is listening for the escape key in all components. This works if only one Popup is on the page at a time, but often UIs get more complicated. A simple example is a Modal dialog with a Select component inside. The user opens the Modal dialog and then opens a Select menu inside the Modal. The user may hit the escape key which should close the Select dropdown menu, but not the Modal dialog. A more painful example is the same scenario, but with click outside detection. The user wants to select an item within the Select dropdown menu, but the Modal dialog detects clicking inside the dropdown menu as an outside click because the dropdown menu isn't a direct child component of the Modal dialog because of the "portalling" technique commonly used.

A stack manager keeps track of all Stacked UI registered on the page as they are opened and closed. A special Window component may be persistent and should be brought to the top of the stack when clicked on. This is how operating system "windows" work. The behavior requires global coordination to determine the order that these popups should be rendered.

Installation

yarn add @workday/canvas-kit-popup-stack

Usage

Note: This is a low-level module meant to be used as a foundation. The @workday/canvas-kit-react-popup module has provided React hooks that wrap this API for easier use with React.

import PopupStack from '@workday/canvas-kit-popup-stack';

const div = document.createElement('div');

// Add to the stack. This will force-set z-index on the element for proper rendering
PopupStack.add({element: div});

// Remove from the stack. This will force-set z-index of other elements in the stack
PopupStack.remove(div);

// Bring current element to the top of the stack. This will force the UI to render the element on top of others
PopupStack.bringToTop(div);

// Will return true if the element is currently the topmost item on the stack
PopupStack.isTopmost(div);

// Returns an array of HTMLElements (note: _not_ the list of stack items)
PopupStack.getElements();

//
PopupStack.contains(element, eventTarget);

API

PopupStackItem

export interface PopupStackItem {
  /**
   * All items in the stack are identified by their DOM element reference. A DOM element is
   * framework agnostic.
   */
  element: HTMLElement;
  /**
   * An owner is typically a trigger or anchor target. For example, it will be a HTMLButtonElement
   * that opened a dropdown menu. If an owner is provided, _and_ that owner element is part of
   * another stack item, it will be considered a "parent" of the provided stack item. This reference
   * helps in the following ways:
   * - Click outside detection typically will use `PopupStack.contains()` which includes this
   *   element. If you wish to close a popup when the target is clicked, add a click handler to do
   *   so.
   * - `PopupStack.bringToTop()` will also bring children to top as well using the `owner` reference
   *   to map a "child" popup back to its parent. This is useful for "Window" or other persistent
   *   popups that are brought to the front when clicked. This will prevent the "Window" from
   *   rendering on top of child popups as they will be brought along also.
   * - Synthetic event systems like in React will bubble events through "portals". This is
   *   inconsistent with DOM event bubbling. This reference helps normalize that behavior across
   *   different frameworks.
   */
  owner?: HTMLElement;
}

add

Adds a PopupStackItem to the stack. This should only be called when the item is rendered to the page. Z-indexes are set when the item is added to the stack. If your application requires popups to be registered initially, but rendered when the user triggers some event, call this method when the event triggers.

PopupStack.add(item: PopupStackItem): void

remove

Removes an item from the stack by its HTMLElement reference. This should be called when a popup is "closed" or when the element is removed from the page entirely to ensure proper memory cleanup. This will not automatically be called when the element is removed from the DOM. Will reset z-index values of the stack

PopupStack.remove(element: HTMLElement): void

isTopmost

Returns true when the provided element is at the top of the stack. It will return false if it is not the top of the stack or is not found in the stack. The element should be the same reference that was passed to add

PopupStack.isTopmost(element: HTMLElement): boolean

getElements

Returns an array of elements defined by the element passed to add.

PopupStack.getElements(): HTMLElement[]

bringToTop

Bring the element to the top of the stack. This is useful for persistent popups to place them on top of the stack when clicked. If an owner was provided to an item when it was added and that owner is a DOM child of another item in the stack, that item will be considered a "parent" to this item. If the previous are true, all "children" stack items will be brought to top as well and will be on top of the element passed to bringToTop. This maintains stack item "hierarchy" so that stack items like Popups and Tooltips don't get pushed behind elements they are supposed to be on top of.

This does not need to be called when a popup is added since added popups are already place on the top of the stack.

PopupStack.bringToTop(element: HTMLElement): void

contains

Compares a Popup by its element reference against the event target and the stack. An event target is considered to be "contained" by an element under the following conditions:

  • The eventTarget is a DOM child of the popup element
  • The eventTarget is the owner element passed when it was added to the stack
  • The eventTarget is a DOM child of the owner element
PopupStack.contains(element: HTMLElement, eventTarget: HTMLElement): boolean
9.1.0-465-next.0

11 months ago

9.0.18

11 months ago

9.1.0-467-next.0

11 months ago

9.0.17

11 months ago

9.1.0-443-next.0

11 months ago

9.1.0-454-next.0

11 months ago

9.1.0-459-next.0

11 months ago

9.1.0-448-next.0

11 months ago

8.6.5

12 months ago

8.6.7

12 months ago

8.6.6

12 months ago

8.6.9

12 months ago

8.6.8

12 months ago

7.2.0-427-next.2

12 months ago

9.1.0-445-next.0

11 months ago

9.1.0-456-next.0

11 months ago

9.1.0-452-next.0

11 months ago

9.0.9

11 months ago

9.0.8

11 months ago

9.0.7

12 months ago

9.0.6

12 months ago

9.0.5

12 months ago

9.0.4

12 months ago

9.0.3

12 months ago

9.0.2

12 months ago

9.0.1

12 months ago

9.0.0

12 months ago

9.1.0-439-next.0

12 months ago

9.1.0-425-next.0

12 months ago

9.1.0-450-next.0

11 months ago

9.1.0-461-next.0

11 months ago

9.1.0-431-next.0

12 months ago

9.0.16

11 months ago

9.0.13

11 months ago

9.0.12

11 months ago

9.0.15

11 months ago

9.0.14

11 months ago

9.0.11

11 months ago

9.0.10

11 months ago

9.1.0-429-next.0

12 months ago

9.1.0-435-next.0

12 months ago

8.6.12

11 months ago

8.6.11

11 months ago

8.6.10

12 months ago

8.6.16

11 months ago

8.6.15

11 months ago

8.6.14

11 months ago

8.6.13

11 months ago

8.6.3

1 year ago

8.6.2

1 year ago

8.6.4

1 year ago

8.6.1

1 year ago

8.6.0

1 year ago

7.4.9

1 year ago

8.5.4

1 year ago

8.5.3

1 year ago

8.5.6

1 year ago

8.5.5

1 year ago

8.5.0

1 year ago

8.5.2

1 year ago

8.5.1

1 year ago

8.5.8

1 year ago

8.5.7

1 year ago

8.5.9

1 year ago

7.4.10

1 year ago

7.4.11

1 year ago

7.4.12

1 year ago

8.5.11

1 year ago

8.5.10

1 year ago

8.5.13

1 year ago

8.5.12

1 year ago

8.4.11

1 year ago

8.4.12

1 year ago

8.4.13

1 year ago

8.3.10

1 year ago

8.3.11

1 year ago

8.3.12

1 year ago

6.9.0-next.0

2 years ago

7.2.0-next.2

2 years ago

7.2.0-next.1

2 years ago

7.2.0-next.0

2 years ago

7.0.12

2 years ago

7.0.13

2 years ago

7.0.10

2 years ago

7.0.11

2 years ago

7.0.14

2 years ago

7.0.15

2 years ago

7.3.0-next.0

2 years ago

7.3.0-next.1

2 years ago

5.3.17

2 years ago

5.3.16

2 years ago

5.3.15

2 years ago

5.3.14

2 years ago

6.9.0-next.4

2 years ago

6.9.0-next.3

2 years ago

6.9.0-next.2

2 years ago

6.9.0-next.6

2 years ago

6.9.0-next.5

2 years ago

8.2.3

1 year ago

8.2.2

1 year ago

8.2.4

1 year ago

7.3.1

2 years ago

7.3.0

2 years ago

7.4.4

1 year ago

7.4.3

2 years ago

7.4.2

2 years ago

7.4.1

2 years ago

7.4.8

1 year ago

7.4.7

1 year ago

7.4.6

1 year ago

7.4.5

1 year ago

8.1.0

1 year ago

8.1.2

1 year ago

8.1.1

1 year ago

6.6.1

2 years ago

6.6.0

2 years ago

8.3.6

1 year ago

8.3.5

1 year ago

8.3.8

1 year ago

7.1.0-next.1

2 years ago

8.3.7

1 year ago

7.1.0-next.0

2 years ago

8.3.2

1 year ago

8.3.1

1 year ago

8.3.4

1 year ago

8.3.3

1 year ago

7.4.0

2 years ago

8.3.9

1 year ago

8.2.1

1 year ago

8.2.0

1 year ago

6.7.0

2 years ago

6.7.2

2 years ago

6.7.1

2 years ago

8.4.5

1 year ago

7.3.14

2 years ago

8.4.4

1 year ago

7.3.13

2 years ago

8.4.7

1 year ago

7.3.16

2 years ago

8.4.6

1 year ago

7.3.15

2 years ago

8.4.1

1 year ago

7.3.10

2 years ago

8.4.0

1 year ago

8.4.3

1 year ago

7.3.12

2 years ago

8.4.2

1 year ago

7.3.11

2 years ago

7.4.0-next.0

2 years ago

8.4.9

1 year ago

7.3.18

2 years ago

7.4.0-next.1

2 years ago

8.4.8

1 year ago

7.4.0-next.2

2 years ago

7.3.17

2 years ago

8.3.0

1 year ago

6.8.1

2 years ago

6.8.0

2 years ago

6.8.3

2 years ago

6.8.2

2 years ago

6.8.5

2 years ago

6.8.4

2 years ago

6.8.7

2 years ago

6.8.6

2 years ago

6.8.9

2 years ago

6.8.8

2 years ago

7.0.8

2 years ago

7.0.7

2 years ago

7.0.6

2 years ago

7.0.5

2 years ago

7.0.9

2 years ago

7.2.11

2 years ago

7.2.10

2 years ago

7.0.0

2 years ago

7.0.4

2 years ago

7.0.3

2 years ago

7.0.2

2 years ago

7.0.1

2 years ago

7.1.5

2 years ago

7.1.4

2 years ago

6.8.15

2 years ago

6.8.14

2 years ago

6.8.13

2 years ago

6.8.12

2 years ago

6.8.11

2 years ago

6.8.10

2 years ago

7.5.0-228-next.0

2 years ago

8.0.9

1 year ago

8.0.8

1 year ago

8.0.5

2 years ago

8.0.4

2 years ago

8.0.7

1 year ago

8.0.6

2 years ago

7.1.3

2 years ago

7.1.2

2 years ago

7.1.1

2 years ago

7.1.0

2 years ago

7.2.6

2 years ago

7.2.5

2 years ago

7.2.4

2 years ago

7.2.3

2 years ago

7.2.9

2 years ago

7.2.8

2 years ago

7.2.7

2 years ago

5.4.0-next.1

2 years ago

7.5.0-220-next.0

2 years ago

8.1.3

1 year ago

7.2.2

2 years ago

7.2.1

2 years ago

7.2.0

2 years ago

8.4.10

1 year ago

7.3.5

2 years ago

7.3.4

2 years ago

7.3.3

2 years ago

7.3.2

2 years ago

7.3.9

2 years ago

7.3.8

2 years ago

7.3.7

2 years ago

7.3.6

2 years ago

8.0.1

2 years ago

8.0.0

2 years ago

8.0.3

2 years ago

8.0.2

2 years ago

6.5.0

2 years ago

6.3.0-next.0

2 years ago

6.3.0-next.1

2 years ago

5.3.0-next.18

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

5.2.9

3 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.5

2 years ago

6.0.4

2 years ago

5.3.0-next.32

2 years ago

6.1.5

2 years ago

5.3.9

2 years ago

5.3.8

2 years ago

5.3.7

2 years ago

5.3.0-next.24

2 years ago

5.3.6

2 years ago

5.3.5

2 years ago

5.3.4

2 years ago

5.3.3

2 years ago

5.3.2

2 years ago

5.3.1

2 years ago

5.3.0

2 years ago

6.1.0

2 years ago

6.1.2

2 years ago

6.1.1

2 years ago

6.1.4

2 years ago

6.1.3

2 years ago

5.3.13

2 years ago

5.3.12

2 years ago

5.3.11

2 years ago

5.3.10

2 years ago

6.5.0-next.0

2 years ago

6.3.10

2 years ago

6.3.11

2 years ago

6.2.1

2 years ago

6.2.0

2 years ago

6.2.3

2 years ago

6.2.2

2 years ago

6.4.0-next.2

2 years ago

6.4.0-next.0

2 years ago

6.4.0-next.1

2 years ago

6.3.4

2 years ago

6.3.3

2 years ago

6.3.6

2 years ago

6.3.5

2 years ago

6.3.8

2 years ago

6.3.7

2 years ago

6.3.9

2 years ago

6.3.0

2 years ago

6.3.2

2 years ago

6.3.1

2 years ago

5.2.12

2 years ago

5.2.11

2 years ago

5.2.10

3 years ago

6.4.3

2 years ago

6.4.2

2 years ago

6.4.5

2 years ago

6.4.4

2 years ago

6.4.6

2 years ago

6.4.1

2 years ago

6.4.0

2 years ago

6.5.1

2 years ago

5.3.0-next.10

3 years ago

5.3.0-next.11

3 years ago

5.2.8

3 years ago

5.2.7

3 years ago

5.3.0-next.9

3 years ago

5.3.0-next.6

3 years ago

5.2.6

3 years ago

5.2.5

3 years ago

5.2.4

3 years ago

5.3.0-next.3

3 years ago

5.3.0-next.2

3 years ago

5.2.3

3 years ago

5.2.2

3 years ago

5.2.1

3 years ago

5.2.0

3 years ago

5.2.1-next.3

3 years ago

5.2.1-next.4

3 years ago

5.2.1-next.2

3 years ago

5.2.1-next.1

3 years ago

5.2.1-next.0

3 years ago

5.1.1-next.11

3 years ago

5.1.1-next.10

3 years ago

5.1.1-next.13

3 years ago

5.1.1-next.12

3 years ago

5.1.1-next.9

3 years ago

5.1.1-next.8

3 years ago

5.1.1-next.7

3 years ago

5.1.1-next.6

3 years ago

5.1.1-next.5

3 years ago

5.1.1-next.4

3 years ago

5.1.1-next.3

3 years ago

5.1.1-next.2

3 years ago

5.0.4-next.34

3 years ago

5.1.0

3 years ago

5.1.1-next.0

3 years ago

5.0.4-next.24

3 years ago

5.0.4-next.23

3 years ago

5.0.4-next.22

3 years ago

5.0.4-next.21

3 years ago

4.8.3

3 years ago

5.0.4-next.28

3 years ago

5.0.4-next.27

3 years ago

5.0.4-next.29

3 years ago

5.0.4-next.31

3 years ago

5.0.4-next.30

3 years ago

5.0.4-next.32

3 years ago

5.0.4-next.20

3 years ago

5.0.4-next.19

3 years ago

5.0.4-next.13

3 years ago

5.0.4-next.12

3 years ago

5.0.4-next.15

3 years ago

5.0.4-next.14

3 years ago

5.0.4-next.17

3 years ago

5.0.4-next.16

3 years ago

5.0.4-next.18

3 years ago

5.0.4-next.8

3 years ago

5.0.4

3 years ago

4.8.2

3 years ago

5.0.4-next.7

3 years ago

5.0.4-next.6

3 years ago

5.0.4-next.5

3 years ago

5.0.4-next.1

3 years ago

5.0.3

3 years ago

4.8.1

3 years ago

5.0.3-next.4

3 years ago

5.0.3-next.5

3 years ago

5.0.3-next.3

3 years ago

5.0.3-next.2

3 years ago

5.0.3-next.1

3 years ago

5.0.3-next.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

4.8.0

3 years ago

5.0.2-next.2

3 years ago

5.0.2-next.1

3 years ago

5.0.2-next.0

3 years ago

5.0.0-rc.0

3 years ago

5.0.0

3 years ago

5.0.1-next.1

3 years ago

5.0.1-next.2

3 years ago

5.0.1-next.3

3 years ago

4.7.1-next.18

3 years ago

4.7.1-next.14

3 years ago

4.7.1-next.15

3 years ago

4.7.1-next.16

3 years ago

5.0.0-beta.2

3 years ago

4.7.1-next.0

3 years ago

4.7.1-next.1

3 years ago

4.7.1-next.2

3 years ago

4.7.1-next.3

3 years ago

4.7.1-next.4

3 years ago

4.7.1-next.5

3 years ago

4.7.1-next.6

3 years ago

4.7.1-next.7

3 years ago

4.7.1-next.8

3 years ago

4.7.1-next.9

3 years ago

4.7.1-next.10

3 years ago

4.7.1-next.11

3 years ago

4.7.1-next.12

3 years ago

5.0.0-beta.1

3 years ago

4.7.0

3 years ago

4.6.1-next.3

3 years ago

4.6.1-next.2

3 years ago

4.6.1-next.0

3 years ago

4.6.1-next.1

3 years ago

4.6.0

3 years ago

4.5.2-next.3

3 years ago

4.5.2-next.1

3 years ago

4.5.2-next.2

3 years ago

4.5.2-next.0

3 years ago

4.5.1-next.3

3 years ago

4.5.1-next.2

3 years ago

4.5.1-next.1

3 years ago

4.5.1-next.4

3 years ago

4.5.1

3 years ago

4.5.1-next.0

3 years ago

4.5.0

3 years ago

4.4.3-next.15

3 years ago

4.4.3-next.14

3 years ago

4.4.3-next.17

3 years ago

4.4.3-next.16

3 years ago

4.4.3-next.18

3 years ago

4.4.3-next.13

3 years ago

4.4.3-next.12

3 years ago

4.4.3-next.11

3 years ago

5.0.0-beta.0

3 years ago

4.4.3-next.10

3 years ago

4.4.3-next.9

3 years ago

4.4.3-next.8

3 years ago

4.4.3-next.7

3 years ago

4.4.3-next.6

3 years ago

4.4.3-next.5

3 years ago

4.4.3-next.4

3 years ago

4.4.3-next.3

3 years ago

4.4.3-next.0

3 years ago

4.4.3-next.1

3 years ago

4.4.2

3 years ago

4.4.2-next.4

3 years ago

4.4.2-next.3

3 years ago

4.4.2-next.2

3 years ago

4.4.1-next.4

3 years ago

4.4.1

3 years ago

4.4.1-next.3

3 years ago

4.4.1-next.2

3 years ago

4.4.1-next.1

3 years ago

4.4.1-next.0

3 years ago

4.4.0

3 years ago

4.3.2-next.6

3 years ago

4.3.2-next.4

3 years ago

4.3.2-next.3

3 years ago

4.3.2-next.5

3 years ago

4.3.2-next.2

3 years ago

4.3.2-next.1

4 years ago

4.3.2-next.0

4 years ago

4.3.1

4 years ago

4.3.1-next.4

4 years ago

4.3.1-next.2

4 years ago

4.3.1-next.3

4 years ago

4.3.1-next.1

4 years ago

4.3.1-next.0

4 years ago

4.1.3-next.28

4 years ago

4.3.0

4 years ago

4.1.3-next.27

4 years ago

4.1.3-next.26

4 years ago

4.1.3-next.25

4 years ago

4.1.3-next.24

4 years ago

4.1.3-next.23

4 years ago

4.1.3-next.22

4 years ago

4.1.3-next.20

4 years ago

4.1.3-next.21

4 years ago

4.1.3-next.17

4 years ago

4.1.3-next.18

4 years ago

4.1.3-next.16

4 years ago

4.2.0

4 years ago

4.1.3-next.15

4 years ago

4.1.3-next.13

4 years ago

4.1.3-next.11

4 years ago

4.1.3-next.12

4 years ago

4.1.3-next.10

4 years ago

4.1.3-next.9

4 years ago

4.1.3-next.8

4 years ago

4.1.3-next.6

4 years ago

4.1.3-next.7

4 years ago

4.1.3-next.4

4 years ago

4.1.3-next.3

4 years ago

4.1.3-next.1

4 years ago

4.1.3-next.0

4 years ago

4.1.2

4 years ago

4.0.3

4 years ago

4.1.2-next.0

4 years ago

4.1.1

4 years ago

4.0.2

4 years ago

4.1.1-next.5

4 years ago

4.1.1-next.4

4 years ago

4.1.1-next.3

4 years ago

4.1.1-next.0

4 years ago

4.1.1-next.2

4 years ago

4.1.0

4 years ago

4.0.1-next.19

4 years ago

4.0.1-next.18

4 years ago

4.0.1-next.17

4 years ago

4.0.1-next.16

4 years ago

4.0.1-next.15

4 years ago

4.0.1-next.14

4 years ago

4.0.1

4 years ago

4.0.1-next.12

4 years ago

4.0.1-next.11

4 years ago

4.0.1-next.9

4 years ago

4.0.1-next.10

4 years ago

4.0.1-next.7

4 years ago

4.0.1-next.8

4 years ago

4.0.1-next.6

4 years ago

4.0.1-next.5

4 years ago

4.0.1-next.4

4 years ago

4.0.1-next.3

4 years ago

4.0.1-next.1

4 years ago

4.0.1-next.2

4 years ago

4.0.1-next.0

4 years ago

4.0.0

4 years ago

4.0.0-beta.5

4 years ago