Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position calculation is sus when the floating element is larger than viewport. #244

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/__tests__/anchored-position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,19 @@ describe('getAnchoredPosition', () => {
expect(top).toEqual(54) // anchorRect.top + anchorRect.height + (settings.anchorOffset ?? 4) - parentRect.top
expect(left).toEqual(380) // anchorRect.left + anchorRect.width - parentRect.left - floatingRect.width
})

// This test runs for values derived from a real use case https://github.com/github/accessibility-audits/issues/4515 as run on a local storybook.
it('should overflow to bottom if the element is too tall to fit on the screen when zoomed', () => {
const parentRect = makeDOMRect(0, 0, 400, 400)
const anchorRect = makeDOMRect(16, 16, 32, 32) // left aligned button
const floatingRect = makeDOMRect(0, 0, 256, 428)
const {float, anchor} = createVirtualDOM(parentRect, anchorRect, floatingRect)
const settings: Partial<PositionSettings> = {side: 'outside-bottom', align: 'start'}
const {top, left, anchorSide, anchorAlign} = getAnchoredPosition(float, anchor, settings)
// Not really sure what to expect here.
expect(anchorSide).toEqual('outside-right')
keithamus marked this conversation as resolved.
Show resolved Hide resolved
expect(anchorAlign).toEqual('start')
expect(top).toEqual(-28) // should be 16 which is the top start of the anchor element. Negative value is wrong.
expect(left).toEqual(52)
})
})
Loading