Skip to content

Commit

Permalink
add permanent placeholder for checkable select field
Browse files Browse the repository at this point in the history
  • Loading branch information
emrberk committed Nov 9, 2023
1 parent 529c58f commit f55986e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/ui/src/Select/CheckableSelectField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
.opener {
input {
cursor: pointer;

&.withPermanentPlaceholder {
color: c.$colorTextSecondary;
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/Select/CheckableSelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type CheckableSelectFieldCoreStaticProps<V> = {
onChange: (newValue: V[]) => void
allSelectedLabel?: string
noneSelectedLabel?: string
permanentPlaceholder?: string
}

export type CheckableSelectFieldExtraProps<V> = {
Expand Down Expand Up @@ -73,6 +74,7 @@ export const CheckableSelectField = <V extends string | number = number>(props:
'data-test': dataTest,
allSelectedLabel = 'All selected',
noneSelectedLabel = 'None selected',
permanentPlaceholder,
noOptionsMessage = 'No options',
id: rootId,
} = props
Expand All @@ -99,6 +101,9 @@ export const CheckableSelectField = <V extends string | number = number>(props:
}, [options, searchValue])

const getValueLabel = () => {
if (permanentPlaceholder) {
return permanentPlaceholder
}
if (value.length === 0) {
return noneSelectedLabel
}
Expand All @@ -123,7 +128,9 @@ export const CheckableSelectField = <V extends string | number = number>(props:
disabled={disabled}
showAriaLabel={showAriaLabel}
helperText={helperText}
className={cls(className, styles.opener)}
className={cls(className, styles.opener, {
[styles.withPermanentPlaceholder]: !!permanentPlaceholder,
})}
error={error}
onBlur={onBlur}
readOnly
Expand Down

0 comments on commit f55986e

Please sign in to comment.