Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add permanent placeholder for checkable select field #525

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading