-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/public-layout-component
- Loading branch information
Showing
14 changed files
with
288 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/internal/components/dropdown/__tests__/dropdown-position.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { applyDropdownPositionRelativeToViewport } from '../../../../../lib/components/internal/components/dropdown/dropdown-position'; | ||
|
||
describe('applyDropdownPositionRelativeToViewport', () => { | ||
const triggerRect = { | ||
blockSize: 50, | ||
inlineSize: 100, | ||
insetBlockStart: 100, | ||
insetInlineStart: 100, | ||
insetBlockEnd: 150, | ||
insetInlineEnd: 200, | ||
}; | ||
|
||
const baseDropdownPosition = { | ||
blockSize: '100px', | ||
inlineSize: '100px', | ||
insetInlineStart: '100px', | ||
dropBlockStart: false, | ||
dropInlineStart: false, | ||
}; | ||
|
||
test("sets block end when the dropdown is anchored to the trigger's block start (expands up)", () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: { ...baseDropdownPosition, dropBlockStart: true }, | ||
isMobile: false, | ||
}); | ||
expect(dropdownElement.style.insetBlockEnd).toBeTruthy(); | ||
expect(dropdownElement.style.insetBlockStart).toBeFalsy(); | ||
}); | ||
|
||
test("aligns block start with the trigger's block end when the dropdown is anchored to the trigger's block end (expands down)", () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: baseDropdownPosition, | ||
isMobile: false, | ||
}); | ||
expect(dropdownElement.style.insetBlockEnd).toBeFalsy(); | ||
expect(dropdownElement.style.insetBlockStart).toEqual(`${triggerRect.insetBlockEnd}px`); | ||
}); | ||
|
||
test("aligns inline start with the trigger's inline start when the dropdown is anchored to the trigger's inline start (anchored from the left in LTR)", () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: baseDropdownPosition, | ||
isMobile: false, | ||
}); | ||
expect(dropdownElement.style.insetInlineStart).toEqual(`${triggerRect.insetInlineStart}px`); | ||
}); | ||
|
||
test("sets inline end when the dropdown is anchored to the trigger's inline start (anchored from the right in LTR)", () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: { ...baseDropdownPosition, dropInlineStart: true }, | ||
isMobile: false, | ||
}); | ||
expect(dropdownElement.style.insetInlineStart).toBeTruthy(); | ||
}); | ||
|
||
test('uses fixed position on desktop', () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: baseDropdownPosition, | ||
isMobile: false, | ||
}); | ||
expect(dropdownElement.style.position).toEqual('fixed'); | ||
}); | ||
|
||
test('uses absolute position on mobile', () => { | ||
const dropdownElement = document.createElement('div'); | ||
applyDropdownPositionRelativeToViewport({ | ||
dropdownElement, | ||
triggerRect, | ||
position: baseDropdownPosition, | ||
isMobile: true, | ||
}); | ||
expect(dropdownElement.style.position).toEqual('absolute'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.