Skip to content

Commit 9a81381

Browse files
committed
fix: menu overflow
1 parent a832e2a commit 9a81381

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ import { SelectPickerOptionType, SelectPickerProps, SelectPickerVariantType } fr
172172
* renderCustomOptions={() => <div />}
173173
* />
174174
* ```
175+
*
176+
* @example Align the menu at the right most end
177+
* ```tsx
178+
* <SelectPicker
179+
* ...
180+
* shouldMenuAlignRight
181+
* />
182+
* ```
175183
*/
176184
const SelectPicker = <OptionValue, IsMulti extends boolean>({
177185
error,
@@ -196,6 +204,7 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
196204
shouldRenderCustomOptions = false,
197205
isSearchable,
198206
selectRef,
207+
shouldMenuAlignRight = false,
199208
...props
200209
}: SelectPickerProps<OptionValue, IsMulti>) => {
201210
const { inputId, required, isDisabled, controlShouldRenderValue = true, value } = props
@@ -223,8 +232,9 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
223232
variant,
224233
getIsOptionValid,
225234
isGroupHeadingSelectable,
235+
shouldMenuAlignRight,
226236
}),
227-
[error, selectSize, menuSize, variant, isGroupHeadingSelectable],
237+
[error, selectSize, menuSize, variant, isGroupHeadingSelectable, shouldMenuAlignRight],
228238
)
229239

230240
// Used to show the create new option for creatable select
@@ -283,7 +293,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
283293
</Tippy>
284294
)
285295

286-
// TODO: fix the right overflow/left overflow issue for menu
287296
return (
288297
<div className="flex column left top dc__gap-4">
289298
{/* Note: Common out for fields */}

src/Shared/Components/SelectPicker/type.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ export type SelectPickerProps<OptionValue = number | string, IsMulti extends boo
143143
selectRef?: IsMulti extends true
144144
? MutableRefObject<SelectInstance<SelectPickerOptionType<OptionValue>, true>>
145145
: MutableRefObject<SelectInstance<SelectPickerOptionType<OptionValue>>>
146+
/**
147+
* If true, the menu is aligned at the right end to prevent going outside of viewport
148+
* in case of menu being larger than the control
149+
*
150+
* @default false
151+
*/
152+
shouldMenuAlignRight?: boolean
146153
} & (IsMulti extends true
147154
? {
148155
isMulti: IsMulti | boolean

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
7979
variant,
8080
getIsOptionValid,
8181
isGroupHeadingSelectable,
82-
}: Pick<SelectPickerProps<OptionValue, IsMulti>, 'error' | 'size' | 'menuSize' | 'variant'> &
82+
shouldMenuAlignRight,
83+
}: Pick<SelectPickerProps<OptionValue, IsMulti>, 'error' | 'size' | 'menuSize' | 'variant' | 'shouldMenuAlignRight'> &
8384
Pick<
8485
SelectPickerProps<OptionValue, IsMulti>['multiSelectProps'],
8586
'getIsOptionValid' | 'isGroupHeadingSelectable'
@@ -101,6 +102,9 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
101102
width: getMenuWidthFromSize(menuSize),
102103
minWidth: '200px',
103104
zIndex: 'var(--select-picker-menu-index)',
105+
...(shouldMenuAlignRight && {
106+
right: 0,
107+
}),
104108
...(getVariantOverrides(variant)?.menu(base, state) || {}),
105109
}),
106110
menuList: (base) => ({
@@ -110,6 +114,7 @@ export const getCommonSelectStyle = <OptionValue, IsMulti extends boolean>({
110114
control: (base, state) => ({
111115
...base,
112116
minHeight: size === ComponentSizeType.medium ? 'auto' : '36px',
117+
minWidth: '56px',
113118
boxShadow: 'none',
114119
backgroundColor: 'var(--N50)',
115120
border: `1px solid ${error ? 'var(--R500)' : 'var(--N200)'}`,

0 commit comments

Comments
 (0)