Skip to content

Commit

Permalink
fix: <SelectInput> styles when isMulti prop is used together with…
Browse files Browse the repository at this point in the history
… `controlShouldRenderValue` (#2490)

* fix: proper SelectInput styles when isMulti used together with controlShouldRenderValue

* fix: add controlShouldRenderValue to default props
  • Loading branch information
kark authored Apr 12, 2023
1 parent ee66b4b commit 26830d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/fast-ducks-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-uikit/select-input': patch
'@commercetools-uikit/select-utils': patch
---

Fix `<SelectInput>` styles when `isMulti` prop is used together with `controlShouldRenderValue`
4 changes: 3 additions & 1 deletion packages/components/inputs/select-input/src/select-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,11 @@ export type TSelectInputProps = {

const defaultProps: Pick<
TSelectInputProps,
'maxMenuHeight' | 'menuPortalZIndex'
'maxMenuHeight' | 'menuPortalZIndex' | 'controlShouldRenderValue'
> = {
maxMenuHeight: 220,
menuPortalZIndex: 1,
controlShouldRenderValue: true,
};

const SelectInput = (props: TSelectInputProps) => {
Expand Down Expand Up @@ -402,6 +403,7 @@ const SelectInput = (props: TSelectInputProps) => {
iconLeft: props.iconLeft,
isMulti: props.isMulti,
hasValue: !isEmpty(selectedOptions),
controlShouldRenderValue: props.controlShouldRenderValue,
isNewTheme,
}) as ReactSelectProps['styles']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type TProps = {
iconLeft?: ReactNode;
isMulti?: boolean;
hasValue?: boolean;
controlShouldRenderValue?: boolean;
};

type TBase = {
Expand Down Expand Up @@ -252,7 +253,8 @@ const valueContainerStyles = (props: TProps) => (base: TBase) => {
// Display property should be Flex when there is an iconLeft, also when the input has some values when isMulti.
// See PR from react select for more insight https://github.com/JedWatson/react-select/pull/4833
display:
(props.iconLeft && !props.isMulti) || (props.isMulti && props.hasValue)
(props.iconLeft && !props.isMulti) ||
(props.isMulti && props.hasValue && props.controlShouldRenderValue)
? 'flex'
: 'grid',
fill:
Expand Down

1 comment on commit 26830d8

@vercel
Copy link

@vercel vercel bot commented on 26830d8 Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.