Skip to content

Commit 0828124

Browse files
authored
Merge pull request #330 from forestream/fix-select
Fix x position logic in SelectContainer
2 parents 58317d1 + 7b9383e commit 0828124

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

.changeset/thick-ways-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/components": patch
3+
---
4+
5+
Fix Select overflow position

packages/components/src/components/Select/__tests__/__snapshots__/index.browser.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exports[`Select > should render with overflow screen 1`] = `
4949
<div
5050
aria-label="Select container"
5151
class="display-0-flex--0 flex-direction-0-column--0 background-0-var(--inputBg,light-dark(#FFF,#2E2E2E))--1 border-0-1px solid var(--border,light-dark(#E4E4E4,#434343))--1 border-radius-0-8px--1 bottom-0--4px--1 box-shadow-0-0 2px 2px 0 var(--base10,light-dark(#0000001A,#FFFFFF1A))--1 height-0-fit-content--1 width-0-fit-content--1 gap-0-6px--1 min-width-0-232px--1 padding-0-10px--1 position-0-fixed--1 user-select-0-none--1 z-index-0-1--1 "
52-
style="top: 10px; left: -1100px; bottom: 778px;"
52+
style="top: 10px; left: 0px; bottom: 778px;"
5353
>
5454
<div
5555
class="display-0-flex--0 align-items-0-center--1 border-radius-0-6px--1 height-0-40px--1 padding-right-0-10px--1 padding-left-0-10px--1 transition-0-background-color .1s ease-in-out--1 color-0-var(--selectDisabled,light-dark(#C4C5D1,#45464D))--1 cursor-0-default--1 font-weight-0-400--1 gap-0-0--1 "

packages/components/src/components/Select/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ export function SelectContainer({
228228
// 요소가 움직일 때마다(스크롤, 리사이즈 등) 위치를 갱신하도록 이벤트를 등록합니다.
229229
const updatePosition = () => {
230230
const {
231-
width,
232231
height,
233232
x: comboboxX,
234233
y: comboboxY,
@@ -241,15 +240,15 @@ export function SelectContainer({
241240
document.documentElement.scrollHeight
242241

243242
const isOverflowRight =
244-
el.offsetWidth + left + window.scrollX + width + x >
243+
el.offsetWidth + left + window.scrollX + x >
245244
document.documentElement.scrollWidth
246245

247246
if (isOverflowBottom)
248247
el.style.bottom = `${window.innerHeight - comboboxY + 10}px`
249248
else el.style.top = `${comboboxY + height + 10 + y}px`
250249

251250
if (isOverflowRight)
252-
el.style.left = `${comboboxX - el.offsetWidth + combobox.offsetWidth + x}px`
251+
el.style.left = `${Math.max(comboboxX - el.offsetWidth + combobox.offsetWidth, 0) + x}px`
253252
else el.style.left = `${comboboxX + x}px`
254253
}
255254

0 commit comments

Comments
 (0)