Skip to content

Commit

Permalink
fix(Select): prevent negative starting position (#1469)
Browse files Browse the repository at this point in the history
(from radix-ui)
  • Loading branch information
sadeghbarati authored Dec 3, 2024
1 parent 9a4038e commit 23283d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/radix-vue/src/Select/SelectItemAlignedPosition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function position() {
const minContentWidth = triggerRect.width + leftDelta
const contentWidth = Math.max(minContentWidth, contentRect.width)
const rightEdge = window.innerWidth - CONTENT_MARGIN
const clampedLeft = clamp(left, CONTENT_MARGIN, rightEdge - contentWidth)
const clampedLeft = clamp(left, CONTENT_MARGIN, Math.max(CONTENT_MARGIN, rightEdge - contentWidth))
contentWrapperElement.value.style.minWidth = `${minContentWidth}px`
contentWrapperElement.value.style.left = `${clampedLeft}px`
Expand All @@ -86,7 +86,7 @@ function position() {
const clampedRight = clamp(
right,
CONTENT_MARGIN,
leftEdge - contentWidth,
Math.max(CONTENT_MARGIN, leftEdge - contentWidth),
)
contentWrapperElement.value.style.minWidth = `${minContentWidth}px`
Expand Down
2 changes: 1 addition & 1 deletion packages/radix-vue/src/Select/SelectViewport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function handleScroll(event: WheelEvent) {
// (independent of the scrollUpButton).
position: 'relative',
flex: 1,
overflow: 'auto',
overflow: 'hidden auto',
}"
@scroll="handleScroll"
>
Expand Down
2 changes: 1 addition & 1 deletion packages/radix-vue/src/shared/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* `min` and `max`.
*/
export function clamp(value: number, min: number = Number.NEGATIVE_INFINITY, max: number = Number.POSITIVE_INFINITY): number {
return Math.min(Math.max(value, min), max)
return Math.min(max, Math.max(min, value))
}

/**
Expand Down

0 comments on commit 23283d2

Please sign in to comment.