@codeleap/web 3.25.4 → 3.25.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/web",
3
- "version": "3.25.4",
3
+ "version": "3.25.5",
4
4
  "main": "src/index.ts",
5
5
  "repository": {
6
6
  "url": "https://github.com/codeleap-uk/internal-libs-monorepo.git",
@@ -233,7 +233,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
233
233
 
234
234
  const _innerInputRef = useRef<any>(null)
235
235
  const innerInputRef = selectRef || _innerInputRef
236
- const innerWrapperRef = useRef(null)
236
+ const innerWrapperRef = useRef<HTMLDivElement>(null)
237
237
 
238
238
  const hasSelectedOptionState = !TypeGuards.isNil(_selectedOption) && TypeGuards.isFunction(_setSelectedOption)
239
239
 
@@ -275,6 +275,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
275
275
  error: !!hasError,
276
276
  focused: isFocused,
277
277
  disabled: isDisabled,
278
+ parentWidth: innerWrapperRef?.current?.clientWidth,
278
279
  })
279
280
 
280
281
  useImperativeHandle(inputRef, () => {
@@ -420,8 +421,7 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
420
421
  tabSelectsValue={false}
421
422
  tabIndex={0}
422
423
  backspaceRemovesValue={true}
423
- // escapeRemoves={true}
424
- // deleteRemoves={true}
424
+ menuPortalTarget={document.body}
425
425
  {...otherProps}
426
426
  {..._props}
427
427
  onKeyDown={isFocused ? handleKeyDown : null}
@@ -436,7 +436,6 @@ export const Select = forwardRef<HTMLInputElement, SelectProps>(
436
436
  defaultOptions={loadOptionsOnMount}
437
437
  ref={innerInputRef}
438
438
  closeMenuOnSelect={closeOnSelect}
439
- menuPortalTarget={innerWrapperRef.current}
440
439
  placeholder={(loadOptionsOnMount && !loadedOptions) ? loadingMessage : placeholder}
441
440
  isDisabled={isDisabled}
442
441
  isClearable={clearable}
@@ -51,6 +51,7 @@ export type ComponentState = {
51
51
  error?: boolean
52
52
  focused?: boolean
53
53
  disabled?: boolean
54
+ parentWidth?: number
54
55
  }
55
56
 
56
57
  export type OptionState = {
@@ -70,6 +71,7 @@ export function useSelectStyles<T, Multi extends boolean>(props: SelectProps<T,
70
71
  error,
71
72
  focused,
72
73
  disabled,
74
+ parentWidth,
73
75
  } = state
74
76
 
75
77
  const variantStyles = useDefaultComponentStyle<'u:Select', typeof SelectPresets>(
@@ -138,10 +140,18 @@ export function useSelectStyles<T, Multi extends boolean>(props: SelectProps<T,
138
140
  wrapper: stylesKey('itemsWrapper'),
139
141
  }
140
142
 
143
+ const parseMenuPortalStyles = (baseStyles: CSSObjectWithLabel) => {
144
+ return {
145
+ ...baseStyles,
146
+ width: parentWidth,
147
+ left: `calc(${baseStyles.left}px - ((${parentWidth}px - ${baseStyles.width}px) / 2))`
148
+ }
149
+ }
150
+
141
151
  const reactSelectStyles: StylesConfig<FormTypes.Option<T>, Multi, GroupBase<FormTypes.Option<T>>> = {
142
152
  container: (baseStyles) => stylesKey('inputContainer', baseStyles),
143
153
  control: () => stylesKey('inputContainer'),
144
- menuPortal: (baseStyles) => stylesKey('listPortal', baseStyles),
154
+ menuPortal: (baseStyles) => stylesKey('listPortal', parseMenuPortalStyles(baseStyles)),
145
155
  menu: (baseStyles) => stylesKey('listWrapper', baseStyles),
146
156
  menuList: (baseStyles) => stylesKey('list', baseStyles),
147
157
  group: () => ({}),