Skip to content

Commit

Permalink
Merge branch 'main' into revert-5560-revert-5504-hectahertz/paginatio…
Browse files Browse the repository at this point in the history
…n-algorithm-enhancements
  • Loading branch information
francinelucca authored Jan 17, 2025
2 parents 8c0c656 + c87e80c commit 8c21754
Showing 4 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-bees-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Fix an issue in useAnnouncements.tsx causing a TypeError in production. The activeItem variable may be null.
5 changes: 5 additions & 0 deletions .changeset/lazy-jars-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Avoid accessing properties of potentially null document.body in PageLayout
7 changes: 4 additions & 3 deletions packages/react/src/FilteredActionList/useAnnouncements.tsx
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import {announce} from '@primer/live-region-element'
import {useEffect, useRef} from 'react'
import type {FilteredActionListProps} from './FilteredActionListEntry'
import type {ItemInput} from '../deprecated/ActionList/List'

// we add a delay so that it does not interrupt default screen reader announcement and queues after it
const delayMs = 500
@@ -28,10 +29,10 @@ const getItemWithActiveDescendant = (
const optionElements = listElement.querySelectorAll('[role="option"]')

const index = Array.from(optionElements).indexOf(activeItemElement)
const activeItem = items[index]
const activeItem = items[index] as ItemInput | undefined

const text = activeItem.text
const selected = activeItem.selected
const text = activeItem?.text
const selected = activeItem?.selected

return {index, text, selected}
}
9 changes: 6 additions & 3 deletions packages/react/src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
@@ -364,21 +364,24 @@ const VerticalDivider: React.FC<React.PropsWithChildren<DividerProps & Draggable
window.addEventListener('keydown', handleKeyDrag)
window.addEventListener('mouseup', handleDragEnd)
window.addEventListener('keyup', handleKeyDragEnd)
document.body.setAttribute('data-page-layout-dragging', 'true')
const body = document.body as HTMLElement | undefined
body?.setAttribute('data-page-layout-dragging', 'true')
} else {
window.removeEventListener('mousemove', handleDrag)
window.removeEventListener('mouseup', handleDragEnd)
window.removeEventListener('keydown', handleKeyDrag)
window.removeEventListener('keyup', handleKeyDragEnd)
document.body.removeAttribute('data-page-layout-dragging')
const body = document.body as HTMLElement | undefined
body?.removeAttribute('data-page-layout-dragging')
}

return () => {
window.removeEventListener('mousemove', handleDrag)
window.removeEventListener('mouseup', handleDragEnd)
window.removeEventListener('keydown', handleKeyDrag)
window.removeEventListener('keyup', handleKeyDragEnd)
document.body.removeAttribute('data-page-layout-dragging')
const body = document.body as HTMLElement | undefined
body?.removeAttribute('data-page-layout-dragging')
}
}, [isDragging, isKeyboardDrag, currentWidth, minWidth, maxWidth])

0 comments on commit 8c21754

Please sign in to comment.