Skip to content

Commit

Permalink
fix(popup): Allow SVG elements in focus calculations (#2331)
Browse files Browse the repository at this point in the history
SVG elements should not be used as popup targets, but we shouldn't be restricting them. This change allows SVG elements to be valid elements when it comes to calculating focus returning and management in the popup system.

Fixes #2330

[category:Components]
  • Loading branch information
NicholasBoll authored Sep 6, 2023
1 parent df9cf08 commit e051ebd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/react/popup/lib/hooks/useReturnFocus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export const useReturnFocus = createElemPropsHook(usePopupModel)(model => {
// should not return focus
const onMouseDown = React.useCallback(
(event: MouseEvent) => {
if (model.state.stackRef.current && event.target instanceof HTMLElement) {
if (!PopupStack.contains(model.state.stackRef.current, event.target)) {
if (model.state.stackRef.current && event.target instanceof Element) {
if (!PopupStack.contains(model.state.stackRef.current, event.target as HTMLElement)) {
elementRef.current = event.target;
}
}
Expand Down Expand Up @@ -119,8 +119,8 @@ export const useReturnFocus = createElemPropsHook(usePopupModel)(model => {
const activeElementOutsidePopupStack =
document.activeElement !== document.body &&
model.state.stackRef.current &&
document.activeElement instanceof HTMLElement &&
!PopupStack.contains(model.state.stackRef.current, document.activeElement);
document.activeElement instanceof Element &&
!PopupStack.contains(model.state.stackRef.current, document.activeElement as HTMLElement);

if (activeElementOutsidePopupStack || requiresFocusChangeRef.current) {
// We need to change focus _before_ the browser process the default action of picking a new
Expand Down

0 comments on commit e051ebd

Please sign in to comment.