Skip to content

Commit 7d3bb47

Browse files
authored
Less sticky metatips (#450)
* working with a11y tip * works for metatip * .filter nit * fixes a11y inspecting some <body> tags * ensure show/hide and removeAll resilience
1 parent 8f5d036 commit 7d3bb47

3 files changed

Lines changed: 41 additions & 25 deletions

File tree

app/features/accessibility.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ const restorePinnedTips = () => {
105105
}
106106

107107
export function hideAll() {
108-
state.tips.forEach(({tip}, target) =>
109-
tip.style.display = 'none')
108+
state.tips.forEach(({tip}, target) => {
109+
if (tip)
110+
tip.style.display = 'none'
111+
})
110112

111113
if (state.active.tip) {
112114
state.active.tip.remove()
@@ -116,10 +118,13 @@ export function hideAll() {
116118

117119
export function removeAll() {
118120
state.tips.forEach(({tip}, target) => {
119-
tip.remove()
121+
tip && tip.remove()
120122
unobserve({tip, target})
121123
})
122124

125+
$('visbug-allytip').forEach(tip =>
126+
tip.remove())
127+
123128
$('[data-allytip]').attr('data-allytip', null)
124129

125130
state.tips.clear()
@@ -209,19 +214,22 @@ const wipe = ({tip, e:{target}}) => {
209214
const togglePinned = els => {
210215
if (state.restoring) return state.restoring = false
211216

212-
els.forEach(el => {
213-
if (!el.hasAttribute('data-allytip')) {
217+
state.tips.forEach(ally => {
218+
if (!els.includes(ally.e.target)) {
219+
ally.e.target.removeAttribute('data-allytip')
220+
wipe(state.tips.get(ally.e.target))
221+
}
222+
})
223+
224+
els
225+
.filter(el => !el.hasAttribute('data-allytip'))
226+
.forEach(el => {
214227
el.setAttribute('data-allytip', true)
215228
state.tips.set(el, {
216229
tip: state.active.tip,
217230
e: {target:el},
218231
})
219232
clearActive()
220-
}
221-
else if (el.hasAttribute('data-allytip')) {
222-
el.removeAttribute('data-allytip')
223-
wipe(state.tips.get(el))
224-
}
225233
})
226234
}
227235

app/features/metatip.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ const restorePinnedTips = () => {
104104
}
105105

106106
export function hideAll() {
107-
state.tips.forEach(({tip}, target) =>
108-
tip.style.display = 'none')
107+
state.tips.forEach(({tip}, target) => {
108+
if (tip)
109+
tip.style.display = 'none'
110+
})
109111

110112
if (state.active.tip) {
111113
state.active.tip.remove()
@@ -115,10 +117,13 @@ export function hideAll() {
115117

116118
export function removeAll() {
117119
state.tips.forEach(({tip}, target) => {
118-
tip.remove()
120+
tip && tip.remove()
119121
unobserve({tip, target})
120122
})
121123

124+
$('visbug-metatip').forEach(tip =>
125+
tip.remove())
126+
122127
$('[data-metatip]').attr('data-metatip', null)
123128

124129
state.tips.clear()
@@ -216,19 +221,22 @@ const wipe = ({tip, e:{target}}) => {
216221
const togglePinned = els => {
217222
if (state.restoring) return state.restoring = false
218223

219-
els.forEach(el => {
220-
if (!el.hasAttribute('data-metatip')) {
224+
state.tips.forEach(meta => {
225+
if (!els.includes(meta.e.target)) {
226+
meta.e.target.removeAttribute('data-metatip')
227+
wipe(state.tips.get(meta.e.target))
228+
}
229+
})
230+
231+
els
232+
.filter(el => !el.hasAttribute('data-metatip'))
233+
.forEach(el => {
221234
el.setAttribute('data-metatip', true)
222235
state.tips.set(el, {
223236
tip: state.active.tip,
224237
e: {target:el},
225238
})
226239
clearActive()
227-
}
228-
else if (el.hasAttribute('data-metatip')) {
229-
el.removeAttribute('data-metatip')
230-
wipe(state.tips.get(el))
231-
}
232240
})
233241
}
234242

app/utilities/styles.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export const getComputedBackgroundColor = el => {
6565
let node = findNearestParentElement(el)
6666
, found = false
6767

68+
if (node.nodeName === 'HTML') {
69+
found = true
70+
background = 'white'
71+
}
72+
6873
while(!found) {
6974
let bg = getStyle(node, 'background-color')
7075

@@ -74,11 +79,6 @@ export const getComputedBackgroundColor = el => {
7479
}
7580

7681
node = findNearestParentElement(node)
77-
78-
if (node.nodeName === 'HTML') {
79-
found = true
80-
background = 'white'
81-
}
8282
}
8383
}
8484

0 commit comments

Comments
 (0)