Reader: fix popover arrow when space is limited

Also make the arrow aria-hidden
This commit is contained in:
John Factotum
2022-10-22 10:14:13 +00:00
committed by GitHub
parent bf9a2699e0
commit 4def05e741
+6 -4
View File
@@ -10,6 +10,7 @@ const createSVGElement = tag =>
const createArrow = down => { const createArrow = down => {
const h = arrowHeight + 1 const h = arrowHeight + 1
const svg = createSVGElement('svg') const svg = createSVGElement('svg')
svg.setAttribute('aria-hidden', 'true')
svg.setAttribute('width', arrowWidth) svg.setAttribute('width', arrowWidth)
svg.setAttribute('height', arrowHeight) svg.setAttribute('height', arrowHeight)
const polygon = createSVGElement('polygon') const polygon = createSVGElement('polygon')
@@ -33,22 +34,23 @@ export const createPopover = (width, height, { x, y }, dir) => {
height: '100vh', height: '100vh',
}) })
const arrow = createArrow(down) const arrow = createArrow(down)
const top = clamp(0, window.innerHeight - (down ? height : fullHeight),
down ? y + arrowHeight : y - fullHeight)
Object.assign(arrow.style, { Object.assign(arrow.style, {
position: 'absolute', position: 'absolute',
left: `${clamp(radius, window.innerWidth - arrowWidth - radius, left: `${clamp(radius, window.innerWidth - arrowWidth - radius,
x - arrowWidth / 2)}px`, x - arrowWidth / 2)}px`,
top: `${clamp(0, window.innerHeight - arrowHeight, top: `${down ? top - arrowHeight : top + height}px`,
down ? y : y - arrowHeight)}px`,
}) })
const popover = document.createElement('div') const popover = document.createElement('div')
popover.setAttribute('role', 'dialog')
popover.classList.add('popover') popover.classList.add('popover')
Object.assign(popover.style, { Object.assign(popover.style, {
position: 'absolute', position: 'absolute',
boxSizing: 'border-box', boxSizing: 'border-box',
overflow: 'hidden', overflow: 'hidden',
left: `${clamp(0, window.innerWidth - width, x - width / 2)}px`, left: `${clamp(0, window.innerWidth - width, x - width / 2)}px`,
top: `${clamp(0, window.innerHeight - fullHeight, top: `${top}px`,
down ? y + arrowHeight : y - fullHeight)}px`,
width: `${width}px`, width: `${width}px`,
height: `${height}px`, height: `${height}px`,
}) })