fix: update design for select component and remove placeholders

This commit is contained in:
Christel Westerberg
2024-12-11 15:02:47 +01:00
parent 241e354fc5
commit ed3879f6d2
10 changed files with 97 additions and 74 deletions

View File

@@ -62,7 +62,6 @@ export default function FormContent() {
items={languageSelect}
label={intl.formatMessage({ id: "Language" })}
name="language"
placeholder={intl.formatMessage({ id: "Select language" })}
/>
</section>
<Divider className={styles.divider} color="subtle" />

View File

@@ -20,8 +20,10 @@ const ageList = [...Array(13)].map((_, i) => ({
value: i,
}))
const childDefaultValues = { age: -1, bed: -1 }
export default function ChildInfoSelector({
child = { age: -1, bed: -1 },
child,
childrenInAdultsBed,
adults,
index = 0,
@@ -89,11 +91,10 @@ export default function ChildInfoSelector({
items={ageList}
label={ageLabel}
aria-label={ageLabel}
value={child.age}
value={child.age ?? childDefaultValues.age}
onSelect={(key) => {
updateSelectedAge(key as number)
}}
placeholder={ageLabel}
maxHeight={180}
name={ageFieldName}
isNestedInModal={true}
@@ -105,11 +106,10 @@ export default function ChildInfoSelector({
items={getAvailableBeds(child.age)}
label={bedLabel}
aria-label={bedLabel}
value={child.bed}
value={child.bed ?? childDefaultValues.bed}
onSelect={(key) => {
updateSelectedBed(key as number)
}}
placeholder={bedLabel}
name={bedFieldName}
isNestedInModal={true}
/>

View File

@@ -138,7 +138,6 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
onSelect={(key: Key) =>
setValue(DateName.day, Number(key))
}
placeholder={dayLabel}
required
tabIndex={3}
value={segment.isPlaceholder ? undefined : segment.value}
@@ -158,7 +157,6 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
onSelect={(key: Key) =>
setValue(DateName.month, Number(key))
}
placeholder={monthLabel}
required
tabIndex={2}
value={segment.isPlaceholder ? undefined : segment.value}
@@ -178,7 +176,6 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) {
onSelect={(key: Key) =>
setValue(DateName.year, Number(key))
}
placeholder={yearLabel}
required
tabIndex={1}
value={segment.isPlaceholder ? undefined : segment.value}

View File

@@ -37,6 +37,11 @@
padding: 0;
}
.container:has(.input:not(:placeholder-shown)) {
align-content: space-around;
gap: var(--Spacing-x-half);
}
.input:not(:active, :focus):placeholder-shown {
height: 0px;
transition: height 150ms ease;

View File

@@ -24,48 +24,47 @@ span.discreet {
order: unset;
}
/* Handle input and textarea fields */
input:active ~ .label,
input:not(:placeholder-shown) ~ .label {
display: block;
font-size: 12px;
}
input:focus ~ .label {
font-size: 12px;
}
input:placeholder-shown ~ .label {
grid-row: 1/-1;
}
input:placeholder-shown:focus ~ .label,
input:placeholder-shown:active ~ .label {
margin-bottom: var(--Spacing-x-half);
}
input:disabled ~ .label {
color: var(--Main-Grey-40);
}
input:not(:placeholder-shown) ~ .label,
textarea:active ~ .label,
textarea:not(:placeholder-shown) ~ .label {
display: block;
font-size: 12px;
}
input:focus ~ .label,
textarea:focus ~ .label {
font-size: 12px;
}
input:placeholder-shown ~ .label,
textarea:placeholder-shown ~ .label {
grid-row: 1/-1;
}
textarea:placeholder-shown:focus ~ .label,
input:placeholder-shown:focus ~ .label,
input:placeholder-shown:active ~ .label,
textarea:placeholder-shown.label,
textarea:placeholder-shown:active ~ .label {
margin-bottom: var(--Spacing-x-half);
}
textarea:disabled ~ .label {
input:disabled ~ .label,
textarea:disabled ~ .label,
:global(.select-container)[data-disabled] .label {
color: var(--Main-Grey-40);
}
/* Handle select fields */
:global(.select-button) .label {
order: unset;
}
:global(.select-container)[data-open="true"] .label:not(.discreet),
:global(.react-aria-SelectValue):has(:nth-child(2)) .label:not(.discreet),
:global(.select-button):active .label:not(.discreet) {
display: grid;
font-size: 12px;
margin-bottom: var(--Spacing-x-half);
}

View File

@@ -9,8 +9,8 @@ export default function Select({
className,
items,
label,
disabled,
name,
placeholder,
registerOptions = {},
}: SelectProps) {
const { control } = useFormContext()
@@ -24,14 +24,13 @@ export default function Select({
<ReactAriaSelect
className={className}
defaultSelectedKey={field.value}
disabled={field.disabled}
disabled={disabled || field.disabled}
items={items}
label={label}
aria-label={label}
name={field.name}
onBlur={field.onBlur}
onSelect={field.onChange}
placeholder={placeholder}
value={field.value}
data-testid={name}
/>

View File

@@ -5,7 +5,7 @@ import type { SelectProps as ReactAriaSelectProps } from "@/components/TempDesig
export interface SelectProps
extends Omit<
React.SelectHTMLAttributes<HTMLSelectElement>,
"name" | "onSelect"
"name" | "onSelect" | "placeholder"
>,
Omit<ReactAriaSelectProps, "onSelect" | "ref" | "value"> {
registerOptions?: RegisterOptions

View File

@@ -32,7 +32,7 @@ export default function Select({
label,
name,
onSelect,
placeholder,
disabled,
required = false,
tabIndex,
value,
@@ -54,45 +54,46 @@ export default function Select({
onSelect(key)
}
let chevronProps = {}
if (discreet) {
chevronProps = { color: "baseButtonTextOnFillNormal" }
} else if (disabled) {
chevronProps = { color: "disabled" }
}
return (
<div className={`${styles.container} ${className}`} ref={setRef}>
<ReactAriaSelect
aria-label={ariaLabel}
className={`${styles.select} ${discreet && styles.discreet}`}
className={`${styles.select} ${discreet ? styles.discreet : ""} select-container`}
defaultSelectedKey={defaultSelectedKey}
name={name}
onSelectionChange={handleOnSelect}
placeholder={placeholder}
selectedKey={value as Key}
onOpenChange={setOverflowVisible}
isDisabled={disabled}
>
<Body asChild fontOnly>
<Button className={styles.input} data-testid={name}>
<span className={styles.inputContentWrapper} tabIndex={tabIndex}>
<SelectValue>
{({ isPlaceholder, selectedText }) => (
<>
<Label
required={required}
size={discreet ? "discreet" : "small"}
>
{label}
{discreet && `:`}
</Label>
{isPlaceholder ? (
placeholder ? (
<Body color="uiTextPlaceholder"> {placeholder}</Body>
) : null
) : (
selectedText
)}
</>
)}
</SelectValue>
</span>
<SelectChevron
{...(discreet ? { color: "baseButtonTextOnFillNormal" } : {})}
/>
<Button
className={`${styles.input} select-button`}
data-testid={name}
>
<SelectValue tabIndex={tabIndex}>
{({ selectedText }) => (
<>
<Label
required={required}
size={discreet ? "discreet" : "regular"}
>
{label}
{discreet && `:`}
</Label>
{selectedText && <Body>{selectedText}</Body>}
</>
)}
</SelectValue>
<SelectChevron {...chevronProps} />
</Button>
</Body>
<Body asChild fontOnly>

View File

@@ -33,11 +33,11 @@
gap: var(--Spacing-x1);
}
.select.discreet .inputContentWrapper {
align-items: center;
justify-content: flex-end;
flex-direction: row;
font-weight: 500;
.select[data-disabled],
.select[data-disabled] .input {
background-color: var(--UI-Input-Controls-Surface-Disabled);
border: none;
pointer-events: none;
}
.input {
@@ -54,14 +54,21 @@
text-align: left;
}
.inputContentWrapper {
.input :global(.react-aria-SelectValue) {
align-items: flex-start;
display: flex;
flex-direction: column;
gap: var(--Spacing-x-half);
flex: 1 0 0;
}
.select.discreet :global(.react-aria-SelectValue) {
align-items: center;
justify-content: flex-end;
flex-direction: row;
font-weight: 500;
gap: var(--Spacing-x-half);
}
.popover {
background-color: var(--Main-Grey-White);
border-radius: var(--Corner-radius-Medium);
@@ -110,3 +117,20 @@
.listBoxItem[data-selected="true"].showRadioButton:before {
box-shadow: inset 0 0 0 8px var(--UI-Input-Controls-Fill-Selected);
}
/* Use global react aria classnames here since setting a css modules classname overrides
the class set by react aria.We use that class to style the child label component. */
.select:not(.discreet) :global(.react-aria-SelectValue) {
display: grid;
transition: height 200ms ease;
}
.input :global(.react-aria-SelectValue) {
height: 18px;
overflow: hidden;
}
.input :global(.react-aria-SelectValue):has(:nth-child(2)) {
height: 38px;
overflow: visible;
}

View File

@@ -7,7 +7,6 @@ export interface SelectProps
label: string
name: string
onSelect: (key: Key) => void
placeholder?: string
value?: string | number
maxHeight?: number
showRadioButton?: boolean