Skip to content

Commit

Permalink
fix(Select): sync label design with form fields (#1506)
Browse files Browse the repository at this point in the history
- remove little used helper mixin, and apply typography to labels
- add overline container to match label structure for textarea and input fields
- update snapshots
- EDS-841
  • Loading branch information
booc0mtaco authored Feb 23, 2023
1 parent 6081760 commit efe9330
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/components/Label/Label.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* Labels can sometimes be marked up as legends for field groups (i.e. radio field).
*/
.label {
@mixin labelStyles;
@mixin eds-theme-typography-form-label;
display: inline-block;
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/components/Select/Select.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,19 @@
/**
* Label on top of the select trigger button to label the select field.
*/
.label {
@mixin eds-theme-typography-label-md;
color: var(--eds-theme-color-form-label);
.select__label {
@mixin eds-theme-typography-form-label;
display: inline-block;
}

/**
* Wraps the Label and the optional/required indicator.
*/
.select__overline {
display: flex;
justify-content: space-between;
margin-bottom: var(--eds-size-half);
color: var(--eds-theme-color-form-label);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,12 @@ const SelectContext = React.createContext<{
const SelectLabel = (props: { className?: string; children: ReactNode }) => {
const { children, className } = props;

const componentClassName = clsx(styles['label'], className);
const componentClassName = clsx(styles['select__label'], className);
const overlineClassName = clsx(styles['select__overline']);
return (
<Listbox.Label className={componentClassName}>{children}</Listbox.Label>
<div className={overlineClassName}>
<Listbox.Label className={componentClassName}>{children}</Listbox.Label>
</div>
);
};

Expand Down
32 changes: 20 additions & 12 deletions src/components/Select/__snapshots__/Select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,17 @@ exports[`<Select /> DefaultWithVisibleLabel story renders snapshot 1`] = `
data-headlessui-state="open"
data-testid="dropdown"
>
<label
class="label"
data-headlessui-state="open"
id="headlessui-listbox-label-:r5:"
<div
class="select__overline"
>
Favorite Animal
</label>
<label
class="select__label"
data-headlessui-state="open"
id="headlessui-listbox-label-:r5:"
>
Favorite Animal
</label>
</div>
<button
aria-controls="headlessui-listbox-options-:r7:"
aria-expanded="true"
Expand Down Expand Up @@ -596,13 +600,17 @@ exports[`<Select /> UsingChildrenProp story renders snapshot 1`] = `
data-headlessui-state="open"
data-testid="dropdown"
>
<label
class="label"
data-headlessui-state="open"
id="headlessui-listbox-label-:rq:"
<div
class="select__overline"
>
Favorite Animal
</label>
<label
class="select__label"
data-headlessui-state="open"
id="headlessui-listbox-label-:rq:"
>
Favorite Animal
</label>
</div>
<button
aria-controls="headlessui-listbox-options-:rs:"
aria-expanded="true"
Expand Down
5 changes: 0 additions & 5 deletions src/design-tokens/mixins.css
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@
}
}

@define-mixin labelStyles {
@mixin eds-theme-typography-form-label;
display: inline-block;
}

@define-mixin placeholderStyles {
color: var(--eds-theme-color-text-disabled);
}
Expand Down

0 comments on commit efe9330

Please sign in to comment.