Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit dd7fa9c

Browse files
author
george
committed
add jsdoc comments to tooltip methods, unify start/stop method descriptions
1 parent e49fb98 commit dd7fa9c

File tree

9 files changed

+66
-21
lines changed

9 files changed

+66
-21
lines changed

js/dist/accordion.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/dropdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/modal.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/tooltip.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/accordion.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ export default class Accordion extends Utils {
6868
// public
6969

7070
/**
71-
* Sets up accordion components and listens to buttons for events.
72-
* Begin listening to [data-accordion-button] elements
71+
* Begin listening to accordions.
7372
*/
7473
start() {
7574
const accordionButtonSelector = this._getPossibleAccordionButtonAttrs(
@@ -86,7 +85,7 @@ export default class Accordion extends Utils {
8685
}
8786

8887
/**
89-
* Stop listening to accordion button events.
88+
* Stop listening to accordions.
9089
*/
9190
stop() {
9291
this._accordionButtons.forEach(button => {

js/src/dropdown.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ export default class Dropdown extends Utils {
7474
// public
7575

7676
/**
77-
* Find and set up dropdown buttons and menus.
78-
* Begin listening to dropdowns for events.
77+
* Begin listening to dropdowns.
7978
*/
8079
start() {
8180
this._dropdowns = nodeListToArray(`${this._dropdownContainerAttr}`)
@@ -94,7 +93,7 @@ export default class Dropdown extends Utils {
9493
}
9594

9695
/**
97-
* Stop listening for dropdown events.
96+
* Stop listening to dropdowns.
9897
*/
9998
stop() {
10099
this._dropdownButtons.forEach(button => {

js/src/modal.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ export default class Modal extends Utils {
6868
// public
6969

7070
/**
71-
* Add accessible attributes to modals.
72-
* Begin listening to elements with [data-modal-button]
71+
* Begin listening to modals.
7372
*/
7473
start() {
7574
this._modals = nodeListToArray(this._modalContainerAttr)
@@ -93,7 +92,7 @@ export default class Modal extends Utils {
9392
}
9493

9594
/**
96-
* Stop listening to modal buttons
95+
* Stop listening to modals
9796
*/
9897
stop() {
9998
this._modalButtons.forEach(button => {
@@ -121,25 +120,20 @@ export default class Modal extends Utils {
121120
this._activeModal = this._activeModalOverlay.querySelector(this._activeModalSelector)
122121
this._activeModalCloseButtons = nodeListToArray(`${this._activeModalSelector} [${Selectors.DATA_CLOSE}]`)
123122

124-
// allow focusable elements to be focused
125123
getFocusableElements(this._activeModalSelector).forEach(element => {
126124
element.setAttribute(Selectors.TABINDEX, "0")
127125
})
128126

129-
// capture focus, stop scrolling, and toggle attributes for visibility
130127
this._handleScrollStop()
131128
this.captureFocus(this._activeModalSelector)
132129
this._activeModalOverlay.setAttribute(Selectors.ARIA_HIDDEN, "false")
133130
this._activeModalOverlay.setAttribute(Selectors.DATA_VISIBLE, "true")
134131

135-
// focus the modal
136132
this._activeModal.setAttribute(Selectors.TABINDEX, "-1")
137133
this._activeModal.focus()
138134

139-
// offset slight scroll caused by this._activeModal.focus()
140135
this._activeModalOverlay.scrollTop = 0
141136

142-
// on ios devices, let the modal close on overlay click
143137
if (iOSMobile) {
144138
this._activeModalOverlay.style.cursor = "pointer"
145139
}
@@ -152,6 +146,10 @@ export default class Modal extends Utils {
152146
})
153147
}
154148

149+
/**
150+
* Setup a modal instance.
151+
* @param {Object} instance - The modal element
152+
*/
155153
_setupModal(instance) {
156154
const modalId = instance.getAttribute(Selectors.DATA_MODAL)
157155

js/src/tooltip.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// TODO: Add tests
2-
31
import { iOSMobile } from "./utils"
42

53
const KeyCodes = {
@@ -52,6 +50,9 @@ export default class Tooltip {
5250

5351
// public
5452

53+
/**
54+
* Begin listening to tooltips.
55+
*/
5556
start() {
5657
this._allTooltips = document.querySelectorAll(`[${Selectors.DATA_TOOLTIP}]`)
5758

@@ -60,6 +61,9 @@ export default class Tooltip {
6061
})
6162
}
6263

64+
/**
65+
* Stop listening to tooltips.
66+
*/
6367
stop() {
6468
this._allTooltips.forEach(instance => {
6569
const id = instance.getAttribute(Selectors.DATA_TOOLTIP)
@@ -72,6 +76,10 @@ export default class Tooltip {
7276

7377
// private
7478

79+
/**
80+
* Render a tooltip.
81+
* @param {Object} event - The event object
82+
*/
7583
_render(event) {
7684
this._activeTrigger = event.target
7785
const tooltipId = this._activeTrigger.getAttribute(Selectors.DATA_TARGET)
@@ -90,6 +98,9 @@ export default class Tooltip {
9098
this._listenForClose()
9199
}
92100

101+
/**
102+
* Close a tooltip.
103+
*/
93104
_handleClose() {
94105
this._hideTooltip()
95106
this._listenForOpen()
@@ -98,14 +109,23 @@ export default class Tooltip {
98109
this._activeTooltip = null
99110
}
100111

112+
/**
113+
* Add data-visible attribute to currently active tooltip.
114+
*/
101115
_showTooltip() {
102116
this._activeTooltip.setAttribute(Selectors.DATA_VISIBLE, "true")
103117
}
104118

119+
/**
120+
* Remove data-visible attribute from currently active tooltip.
121+
*/
105122
_hideTooltip() {
106123
this._activeTooltip.setAttribute(Selectors.DATA_VISIBLE, "false")
107124
}
108125

126+
/**
127+
* Stop listening for render events, and start listening to close events.
128+
*/
109129
_listenForClose() {
110130
this._activeTrigger.removeEventListener(Events.MOUSEOVER, this._render)
111131
this._activeTrigger.removeEventListener(Events.FOCUS, this._render)
@@ -118,12 +138,19 @@ export default class Tooltip {
118138
}
119139
}
120140

141+
/**
142+
* Close a tooltip with the escape key.
143+
* @param {Object} event - The event object
144+
*/
121145
_handleEscapeKeyPress(event) {
122146
if (event.which === KeyCodes.ESCAPE) {
123147
this._handleClose()
124148
}
125149
}
126150

151+
/**
152+
* Stop listening to close events, start listening for render events.
153+
*/
127154
_listenForOpen() {
128155
this._activeTrigger.removeEventListener(Events.MOUSEOUT, this._handleClose)
129156
this._activeTrigger.removeEventListener(Events.BLUR, this._handleClose)
@@ -136,6 +163,10 @@ export default class Tooltip {
136163
}
137164
}
138165

166+
/**
167+
* Aligns a tooltip vertically or horizontally.
168+
* @param {String} property - String specifying "height" or "width"
169+
*/
139170
_alignTooltip(property) {
140171
const triggerLength = this._getComputedLength(this._activeTrigger, property)
141172
const tooltipLength = this._getComputedLength(this._activeTooltip, property)
@@ -152,6 +183,10 @@ export default class Tooltip {
152183
}
153184
}
154185

186+
/**
187+
* Setup a tooltip and trigger with appropriate event listeners and attributes.
188+
* @param {Object} instance - A tooltip instance
189+
*/
155190
_setupTooltip(instance) {
156191
const id = instance.getAttribute(Selectors.DATA_TOOLTIP)
157192
const trigger = instance.querySelector(this._getTrigger(id))
@@ -176,14 +211,29 @@ export default class Tooltip {
176211
trigger.addEventListener(Events.FOCUS, this._render)
177212
}
178213

214+
/**
215+
* Get an attribute selector string.
216+
* @param {String} id - A unique tooltip id
217+
* @return {String}
218+
*/
179219
_getTrigger(id) {
180220
return `[${Selectors.DATA_TARGET}="${id}"]`
181221
}
182222

223+
/**
224+
* Render a tooltip.
225+
* @param {Object} element - A tooltip element
226+
* @param {String} property - The "height" or "width" property.
227+
* @return {Number}
228+
*/
183229
_getComputedLength(element, property) {
184230
return parseInt(window.getComputedStyle(element)[property].slice(0, -2))
185231
}
186232

233+
/**
234+
* Determine if a tooltip is rendering on the left or right.
235+
* @return {Boolean}
236+
*/
187237
_isLeftOrRight() {
188238
const classes = this._activeTooltip.classList
189239
return classes.contains(Selectors.DROP_LEFT_CLASS) || classes.contains(Selectors.DROP_RIGHT_CLASS)

scss/_config.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ $dropdown-menu-header-font-size: 14px !default;
736736
$dropdown-menu-header-padding: 12px !default;
737737
$dropdown-menu-header-color: $gray800 !default;
738738

739-
740739
// 9. Tooltips
741740
// -----------
742741

0 commit comments

Comments
 (0)