Skip to content

Commit

Permalink
feat(form-control): add hidden label instead min-width
Browse files Browse the repository at this point in the history
  • Loading branch information
reme3d2y committed Apr 9, 2021
1 parent 147bb71 commit a40ffcf
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 222 deletions.
24 changes: 24 additions & 0 deletions packages/bank-card/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ exports[`BankCard Snapshots tests should match snapshots 1`] = `
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
Номер карты или счёта
</span>
<div
class="label label"
>
Expand Down Expand Up @@ -148,6 +154,12 @@ exports[`BankCard Snapshots tests should match snapshots 2`] = `
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
Номер карты или счёта
</span>
<div
class="label label"
>
Expand Down Expand Up @@ -255,6 +267,12 @@ exports[`BankCard Snapshots tests should match snapshots 3`] = `
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
Номер карты или счёта
</span>
<div
class="label label"
>
Expand Down Expand Up @@ -362,6 +380,12 @@ exports[`BankCard Snapshots tests should match snapshots 4`] = `
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
Номер карты или счёта
</span>
<div
class="label label"
>
Expand Down
11 changes: 8 additions & 3 deletions packages/form-control/src/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,14 @@ export const FormControl = React.forwardRef<HTMLDivElement, FormControlProps>(

<div className={styles.inputWrapper}>
{label && (
<div className={cn(styles.label, labelClassName)}>
<span className={styles.labelInner}>{label}</span>
</div>
<React.Fragment>
<span className={styles.hiddenLabel} aria-hidden={true}>
{label}
</span>
<div className={cn(styles.label, labelClassName)}>
<span className={styles.labelInner}>{label}</span>
</div>
</React.Fragment>
)}

<div className={styles.input}>{children}</div>
Expand Down
16 changes: 16 additions & 0 deletions packages/form-control/src/__snapshots__/Component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ Object {
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
<span>
This is label
</span>
</span>
<div
class="label"
>
Expand Down Expand Up @@ -551,6 +559,14 @@ Object {
<div
class="inputWrapper"
>
<span
aria-hidden="true"
class="hiddenLabel"
>
<span>
This is label
</span>
</span>
<div
class="label"
>
Expand Down
12 changes: 12 additions & 0 deletions packages/form-control/src/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@
transform: scaleY(2);
}

.hiddenLabel {
opacity: 0;
height: 0;
padding: var(--form-control-paddings);
display: block;
box-sizing: border-box;
}

.l .hiddenLabel {
padding: var(--form-control-l-paddings);
}

/* min-height and width: max-content; fix for IE */

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
Expand Down

0 comments on commit a40ffcf

Please sign in to comment.