Skip to content

Commit 32848a9

Browse files
authored
fix: center text for no-label-float attribute in contour style input (#119)
* fix: center text for no label float attribute in contour style input * fix: grouped decendant selectors under the same declaration([no-label-float])
1 parent f8a6cc8 commit 32848a9

File tree

3 files changed

+48
-16
lines changed

3 files changed

+48
-16
lines changed

src/styles.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ export const styles = css`
110110
text-transform: var(--cosmoz-input-label-text-transform);
111111
font-weight: var(--cosmoz-input-label-font-weight);
112112
}
113-
.wrap:has(#input:not(:placeholder-shown)) slot[name='suffix']::slotted(*),
114-
.wrap:has(#input:not(:placeholder-shown)) slot[name='prefix']::slotted(*) {
115-
transform: translateY(var(--label-translate-y));
113+
114+
.wrap:has(#input:not(:placeholder-shown)) {
115+
slot[name='suffix']::slotted(*),
116+
slot[name='prefix']::slotted(*) {
117+
transform: translateY(var(--label-translate-y));
118+
}
116119
}
120+
117121
:host([always-float-label]) label,
118122
#input:not(:placeholder-shown) + label {
119123
transform: translateY(
@@ -128,9 +132,11 @@ export const styles = css`
128132
transform: translateY(var(--label-translate-y));
129133
}
130134
131-
:host([always-float-label]) slot[name='suffix']::slotted(*),
132-
:host([always-float-label]) slot[name='prefix']::slotted(*) {
133-
transform: translateY(var(--label-translate-y));
135+
:host([always-float-label]) {
136+
slot[name='suffix']::slotted(*),
137+
slot[name='prefix']::slotted(*) {
138+
transform: translateY(var(--label-translate-y));
139+
}
134140
}
135141
136142
:host(:not(always-float-label):focus-within) #input::placeholder,
@@ -139,12 +145,29 @@ export const styles = css`
139145
opacity: 1;
140146
}
141147
148+
:host([no-label-float]) {
149+
.float,
150+
label {
151+
display: none;
152+
}
153+
154+
#input:not(:placeholder-shown) {
155+
transform: translateY(0%);
156+
}
157+
158+
.wrap:has(#input:not(:placeholder-shown)) slot[name='suffix']::slotted(*),
159+
.wrap:has(#input:not(:placeholder-shown)) slot[name='prefix']::slotted(*) {
160+
transform: translateY(0%);
161+
}
162+
}
163+
142164
.line {
143165
padding-top: 1px;
144166
border-bottom: 1px solid var(--line-color);
145167
position: relative;
146168
display: var(--cosmoz-input-line-display, block);
147169
}
170+
148171
.line::before {
149172
content: '';
150173
position: absolute;
@@ -175,11 +198,6 @@ export const styles = css`
175198
opacity: var(--disabled-line-opacity);
176199
}
177200
178-
:host([no-label-float]) .float,
179-
:host([no-label-float]) label {
180-
display: none;
181-
}
182-
183201
.error {
184202
font-size: 12px;
185203
line-height: 20px;

stories/cosmoz-input.stories.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ export const contour = () => html`
5454
<style>
5555
cosmoz-input {
5656
--cosmoz-input-color: #aeacac;
57-
--cosmoz-input-border-radius: 4px;
58-
--cosmoz-input-wrap-padding: 12px;
57+
--cosmoz-input-border-radius: 8px;
58+
--cosmoz-input-wrap-padding: 12px 16px;
59+
--cosmoz-input-padding: 14px 0px;
5960
--cosmoz-input-line-display: none;
6061
--cosmoz-input-contour-size: 1px;
61-
--cosmoz-input-label-translate-y: 10px;
62+
--cosmoz-input-label-translate-y: 8px;
6263
--cosmoz-input-float-display: none;
63-
--cosmoz-input-padding: 10px 8px;
6464
}
6565
span {
6666
margin: 0 4px;
@@ -78,7 +78,16 @@ export const contour = () => html`
7878
<cosmoz-input always-float-label .label=${'This label always floats'}
7979
><span slot="prefix">${'Example:'}</span></cosmoz-input
8080
>
81-
81+
<cosmoz-input
82+
no-label-float
83+
.label=${'This label never floats'}
84+
></cosmoz-input>
85+
<cosmoz-input no-label-float .label=${'This label never floats with prefix'}
86+
><span slot="prefix">${'Example:'}</span></cosmoz-input
87+
>
88+
<cosmoz-input no-label-float .label=${'This label never floats with sufix'}
89+
><span slot="suffix">${'suffix'}</span></cosmoz-input
90+
>
8291
<cosmoz-input
8392
invalid
8493
.label=${'This input is invalid!'}

stories/cosmoz-textarea.stories.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const basic = () => html`
4343
.label=${'Write your comment here'}
4444
.value=${loremIpsum}
4545
></cosmoz-textarea>
46+
<cosmoz-textarea
47+
no-label-float
48+
placeholder=${'Write your comment here'}
49+
.value=${loremIpsum}
50+
></cosmoz-textarea>
4651
<cosmoz-textarea
4752
invalid
4853
.errorMessage=${'Something is rotten in the state of Denmark'}

0 commit comments

Comments
 (0)