diff --git a/change/@fluentui-react-aria-95b07b56-fae4-4b3b-bb62-beab45149e11.json b/change/@fluentui-react-aria-95b07b56-fae4-4b3b-bb62-beab45149e11.json new file mode 100644 index 0000000000000..bbe84f8a3882c --- /dev/null +++ b/change/@fluentui-react-aria-95b07b56-fae4-4b3b-bb62-beab45149e11.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "chore: remove optional \"win\" argument", + "packageName": "@fluentui/react-aria", + "email": "seanmonahan@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-aria/src/activedescendant/scrollIntoView.test.ts b/packages/react-components/react-aria/src/activedescendant/scrollIntoView.test.ts index 9188534869416..650471f168c68 100644 --- a/packages/react-components/react-aria/src/activedescendant/scrollIntoView.test.ts +++ b/packages/react-components/react-aria/src/activedescendant/scrollIntoView.test.ts @@ -75,6 +75,9 @@ describe('scrollIntoView', () => { offsetParent: listbox as HTMLElement, parentElement: listbox as HTMLElement, contains: jest.fn().mockReturnValue(false), + ownerDocument: { + defaultView: window, + } as Document, }; jest @@ -118,6 +121,9 @@ describe('scrollIntoView', () => { offsetParent: listbox as HTMLElement, parentElement: listbox as HTMLElement, contains: jest.fn().mockReturnValue(false), + ownerDocument: { + defaultView: window, + } as Document, }; jest @@ -187,36 +193,4 @@ describe('scrollIntoView', () => { expect(mockAncestorScrollTo).toHaveBeenCalledWith(0, 122); }); - - it('should use the provided `window` argument', () => { - listboxGrandParent = { - ...listboxGrandParent, - scrollTop: 0, - }; - listboxParent = { - ...listboxParent, - offsetParent: listboxGrandParent as Element, - parentElement: listboxGrandParent as HTMLElement, - }; - listbox = { - ...listbox, - scrollHeight: 100, - offsetHeight: 100, - offsetParent: listboxGrandParent as Element, - parentElement: listboxParent as HTMLElement, - }; - const option: Partial = { - offsetHeight: 10, - offsetTop: 160, - offsetParent: listboxGrandParent as HTMLElement, - parentElement: listbox as HTMLElement, - contains: jest.fn().mockReturnValue(false), - }; - - const getComputedStyleSpy = jest.spyOn(window, 'getComputedStyle'); - - scrollIntoView(option as HTMLElement); - - expect(getComputedStyleSpy).toHaveBeenCalledTimes(1); - }); }); diff --git a/packages/react-components/react-aria/src/activedescendant/scrollIntoView.ts b/packages/react-components/react-aria/src/activedescendant/scrollIntoView.ts index 3ca94fe44b16e..771f4941e3a08 100644 --- a/packages/react-components/react-aria/src/activedescendant/scrollIntoView.ts +++ b/packages/react-components/react-aria/src/activedescendant/scrollIntoView.ts @@ -1,11 +1,8 @@ -export const scrollIntoView = (target: HTMLElement | null | undefined, winArg?: Window | null) => { +export const scrollIntoView = (target: HTMLElement | null | undefined) => { if (!target) { return; } - // eslint-disable-next-line no-restricted-globals - const win = winArg ?? window; - const scrollParent = findScrollableParent(target.parentElement as HTMLElement); if (!scrollParent) { return; @@ -14,7 +11,7 @@ export const scrollIntoView = (target: HTMLElement | null | undefined, winArg?: const { offsetHeight } = target; const offsetTop = getTotalOffsetTop(target, scrollParent); - const { scrollMarginTop, scrollMarginBottom } = getScrollMargins(target, win); + const { scrollMarginTop, scrollMarginBottom } = getScrollMargins(target); const { offsetHeight: parentOffsetHeight, scrollTop } = scrollParent; @@ -55,7 +52,15 @@ const getTotalOffsetTop = (element: HTMLElement, scrollParent: HTMLElement): num return element.offsetTop + getTotalOffsetTop(element.offsetParent as HTMLElement, scrollParent); }; -const getScrollMargins = (element: HTMLElement, win: Window) => { +const getScrollMargins = (element: HTMLElement) => { + const win = element.ownerDocument?.defaultView; + if (!win) { + return { + scrollMarginTop: 0, + scrollMarginBottom: 0, + }; + } + const computedStyles = win.getComputedStyle(element); const scrollMarginTop = getIntValueOfComputedStyle(computedStyles.scrollMarginTop) ?? diff --git a/packages/react-components/react-aria/src/activedescendant/useActiveDescendant.ts b/packages/react-components/react-aria/src/activedescendant/useActiveDescendant.ts index 33413f848f42a..0512298e8e968 100644 --- a/packages/react-components/react-aria/src/activedescendant/useActiveDescendant.ts +++ b/packages/react-components/react-aria/src/activedescendant/useActiveDescendant.ts @@ -1,5 +1,4 @@ import * as React from 'react'; -import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts'; import { useEventCallback, useMergedRefs } from '@fluentui/react-utilities'; import { useOnKeyboardNavigationChange } from '@fluentui/react-tabster'; import { useOptionWalker } from './useOptionWalker'; @@ -33,8 +32,6 @@ export function useActiveDescendant(null); const activeParentRef = React.useRef(null); const attributeVisibilityRef = React.useRef(true); - const { targetDocument } = useFluent(); - const win = targetDocument?.defaultView; const removeAttribute = React.useCallback(() => { activeParentRef.current?.removeAttribute('aria-activedescendant'); @@ -90,7 +87,7 @@ export function useActiveDescendant