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

feat(textarea): fix material textarea label positioning #1518

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/components/textarea/textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,12 @@ export default class IgcTextareaComponent extends FormAssociatedRequiredMixin(
part=${partNameMap({
...this.resolvePartNames(),
labelled: this.label,
placeholder: this.placeholder,
})}
>
<div part="start">${this.renderPrefix()}</div>
<div part="notch">${this.renderLabel()}</div>
${this.renderInput()}
<div part="notch">${this.renderLabel()}</div>
<div part="filler"></div>
<div part="end">${this.renderSuffix()}</div>
</div>
Expand Down
84 changes: 58 additions & 26 deletions src/components/textarea/themes/shared/textarea.material.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ textarea {
padding-inline: rem(4px);
}

[part='label'] {
position: absolute;
transform-origin: top left;
top: calc($input-top-padding - #{rem(2px)});
padding-inline-end: rem(4px);
transition:
transform 150ms cubic-bezier(.4, 0, .2, 1),
color 150ms cubic-bezier(.4, 0, .2, 1),
font-size 150ms cubic-bezier(.4, 0, .2, 1);
will-change: transform;
}

%label-filled {
transform: translateY(0);
top: calc(#{$input-top-padding} / 4);
font-size: rem(12px);
}

%label-outlined-filled {
display: inline-block;
position: relative;
inset-block: 0;
transform: translateY(-50%);
margin-block-end: auto;
padding-inline-end: 0;
font-size: rem(12px);
}

:host(:not([outlined])) {
[part~='container'] {
overflow: hidden;
Expand All @@ -57,6 +85,12 @@ textarea {
grid-area: 1 / 2 / span 1 / span 3;
}
}

textarea:placeholder-shown + [part='notch'] [part='label'],
textarea:placeholder-shown ~ [part='notch'] [part='label'],
[part~='filled'] [part='notch'] [part='label'] {
@extend %label-filled;
}
}

:host(:not([outlined]):hover) {
Expand Down Expand Up @@ -104,6 +138,8 @@ textarea {

:host(:focus-within) {
[part~='label'] {
@extend %label-filled;

color: var-get($theme, 'focused-secondary-color');
}
}
Expand Down Expand Up @@ -142,19 +178,6 @@ textarea {
}
}

[part~='label'] {
position: absolute;
max-width: 100%;
padding-inline-end: rem(4px);
line-height: normal;
backface-visibility: hidden;
will-change: transform;
transform-origin: top left;
transform: translateY(0);
top: calc(#{$input-top-padding} / 4);
font-size: rem(12px);
}

[part='start'],
[part='end'] {
display: flex;
Expand Down Expand Up @@ -224,6 +247,18 @@ textarea {
}
}

[part~='container'][part~='filled'],
[part~='container'][part~='placeholder'] {
[part='notch'] {
border-block-start-color: transparent;
}
}

[part~='placeholder'] [part='label'],
[part~='filled'] [part='label'] {
@extend %label-outlined-filled;
}

[part='start'] {
width: auto;
border: {
Expand All @@ -246,16 +281,6 @@ textarea {
}
}

[part~='label'] {
top: 0;
transform: translateY(-50%);
margin-block-end: auto;
padding-inline-end: 0;
display: inline-block;
position: relative;
background: transparent;
}

[part='filler'] {
border: {
width: rem(1px);
Expand All @@ -267,8 +292,7 @@ textarea {
}

[part='notch'] {
border-block-start-color: transparent;
border-block-end: rem(1px) solid var-get($theme, 'border-color');
border-block: rem(1px) solid var-get($theme, 'border-color');
padding: 0 rem(4px);

&:empty {
Expand Down Expand Up @@ -313,11 +337,16 @@ textarea {
border-block-width: rem(2px);
}

[part='label'] {
@extend %label-outlined-filled;
}

[part='filler'] {
border-block-color: var-get($theme, 'focused-border-color');
}

[part='notch'] {
border-block-start-color: transparent;
border-block-end-color: var-get($theme, 'focused-border-color');
}

Expand Down Expand Up @@ -364,10 +393,13 @@ textarea {
:host([invalid][outlined]:not([disabled]):focus-within) {
[part='start'],
[part='filler'],
[part='notch'],
[part='end'] {
border-color: var-get($theme, 'error-secondary-color');
}

[part='notch'] {
border-block-end-color: var-get($theme, 'error-secondary-color');
}
}

:host(:disabled[outlined]),
Expand Down
4 changes: 2 additions & 2 deletions stories/textarea.stories.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sourceCode } from '@igniteui/material-icons-extended';
import type { Meta, StoryObj } from '@storybook/web-components';
import { html, render } from 'lit';
import { html, nothing, render } from 'lit';

import {
IgcIconComponent,
Expand Down Expand Up @@ -267,7 +267,7 @@ export const Default: Story = {
name=${ifDefined(args.name)}
label=${args.label}
rows=${args.rows}
placeholder=${args.placeholder}
placeholder=${args.placeholder || nothing}
resize=${args.resize}
value=${ifDefined(args.value)}
minlength=${ifDefined(args.minLength)}
Expand Down
Loading