Skip to content

Commit fd605d5

Browse files
asynclizcopybara-github
authored andcommitted
feat(field): add resizability
PiperOrigin-RevId: 512747965
1 parent b310e6b commit fd605d5

File tree

5 files changed

+28
-40
lines changed

5 files changed

+28
-40
lines changed

field/lib/_content.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ $_enter-delay: $_label-duration - $_visible-duration;
2525
.middle,
2626
.end {
2727
display: flex;
28-
align-items: center;
2928
box-sizing: border-box;
3029
height: 100%;
3130
// Relative position for absolutely positioned labels (to avoid interfering
@@ -43,6 +42,7 @@ $_enter-delay: $_label-duration - $_visible-duration;
4342

4443
.start,
4544
.end {
45+
align-items: center;
4646
justify-content: center;
4747
}
4848

@@ -61,6 +61,7 @@ $_enter-delay: $_label-duration - $_visible-duration;
6161
}
6262

6363
.middle {
64+
align-items: stretch;
6465
// The container of the field aligns sections by "center". Only the middle
6566
// section opts in to baseline alignment.
6667
//

field/lib/_filled-field.scss

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,31 @@ $_md-sys-motion: tokens.md-sys-motion-values();
3535
}
3636
}
3737

38-
.container {
39-
// Needed for negative z-index below to place background and state layer
40-
// behind content.
41-
z-index: 0;
42-
43-
// ::before is used for background color so that opacity may be changed
44-
// without affecting content
45-
&::before {
46-
background: var(--_container-color);
47-
}
48-
49-
// ::after is used for the state layer color and opacity
50-
&::after {
51-
visibility: hidden;
52-
}
53-
54-
&::before,
55-
&::after {
56-
border-radius: inherit;
57-
content: '';
58-
display: flex;
59-
height: 100%;
60-
position: absolute;
61-
width: 100%;
62-
z-index: -1;
63-
}
38+
.background,
39+
.state-layer {
40+
border-radius: inherit;
41+
inset: 0;
42+
pointer-events: none;
43+
position: absolute;
6444
}
6545

66-
.label.floating {
67-
position: absolute;
68-
top: 0;
46+
.background {
47+
background: var(--_container-color);
6948
}
7049

7150
.state-layer {
72-
border-radius: inherit;
73-
height: 100%;
74-
position: absolute;
75-
width: 100%;
7651
visibility: hidden;
77-
z-index: -1;
7852
}
7953

8054
.field:not(.disabled):hover .state-layer {
8155
visibility: visible;
8256
}
8357

58+
.label.floating {
59+
position: absolute;
60+
top: 0;
61+
}
62+
8463
.active-indicator {
8564
inset: auto 0 0 0;
8665
// Prevent click events on the indicator element since it has no width and
@@ -150,7 +129,7 @@ $_md-sys-motion: tokens.md-sys-motion-values();
150129
opacity: var(--_disabled-active-indicator-opacity);
151130
}
152131

153-
.disabled .container::before {
132+
.disabled .background {
154133
background: var(--_disabled-container-color);
155134
opacity: var(--_disabled-container-opacity);
156135
}

field/lib/_shared.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
}
1919

2020
.field {
21-
display: inline-flex;
21+
display: flex;
2222
flex: 1;
2323
flex-direction: column;
2424
// Allow the use of block/inline reflexive RTL properties without impacting
2525
// structure when languages change.
2626
writing-mode: horizontal-tb;
27+
max-width: 100%; // Do not allow field to grow beyond explicitly set width
2728
}
2829

2930
// A separate wrapper is needed around the container for the outline, whose
@@ -41,15 +42,19 @@
4142
.container {
4243
align-items: center;
4344
border-radius: inherit;
44-
box-sizing: border-box;
4545
display: flex;
4646
flex: 1;
47+
min-width: min-content;
4748
overflow: hidden;
4849
padding-top: var(--_container-padding-vertical);
4950
padding-bottom: var(--_container-padding-vertical);
5051
position: relative;
5152
}
5253

54+
.resizable .container {
55+
resize: both;
56+
}
57+
5358
.disabled {
5459
pointer-events: none;
5560
}

field/lib/field.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class Field extends LitElement {
1919
@property({type: Boolean}) focused = false;
2020
@property({type: String}) label?: string;
2121
@property({type: Boolean}) populated = false;
22+
@property({type: Boolean}) resizable = false;
2223
@property({type: Boolean}) required = false;
2324

2425
/**
@@ -65,6 +66,7 @@ export class Field extends LitElement {
6566
'with-start': this.hasStart,
6667
'with-end': this.hasEnd,
6768
'populated': this.populated,
69+
'resizable': this.resizable,
6870
'required': this.required,
6971
'no-label': !this.label,
7072
};
@@ -73,9 +75,9 @@ export class Field extends LitElement {
7375
<div class="field ${classMap(classes)}">
7476
<div class="container-overflow">
7577
${outline}
78+
${this.renderBackground?.()}
79+
${this.renderIndicator?.()}
7680
<div class="container">
77-
${this.renderBackground?.()}
78-
${this.renderIndicator?.()}
7981
<div class="start">
8082
<slot name="start"></slot>
8183
</div>

field/lib/filled-field.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {Field} from './field.js';
1414
export class FilledField extends Field {
1515
protected override renderBackground() {
1616
return html`
17+
<div class="background"></div>
1718
<div class="state-layer"></div>
1819
`;
1920
}

0 commit comments

Comments
 (0)