Skip to content

Commit

Permalink
fix!: make prefix, suffix and clear button stick to top (#7895)
Browse files Browse the repository at this point in the history
* make prefix/suffix/clear button sticky

* add test

* fix material theme

* simplify selectors
  • Loading branch information
sissbruecker authored Oct 2, 2024
1 parent fd28a42 commit 21ab55d
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/text-area/test/visual/lumo/text-area.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ describe('text-area', () => {
await visualDiff(div, 'scrolled');
});

it('scrolled with prefix, suffix, clear button', async () => {
const prefix = document.createElement('span');
prefix.setAttribute('slot', 'prefix');
prefix.textContent = '$';
element.appendChild(prefix);

const suffix = document.createElement('span');
suffix.setAttribute('slot', 'suffix');
suffix.textContent = '$';
element.appendChild(suffix);

element.clearButtonVisible = true;
element.style.height = '70px';
element.value = 'a\nb\nc\nd\ne';
element.focus();
await visualDiff(div, 'scrolled-with-prefix-suffix-clear-button');
});

it('error message', async () => {
element.label = 'Label';
element.errorMessage = 'This field is required';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/text-area/test/visual/material/text-area.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ describe('text-area', () => {
await visualDiff(div, 'scrolled');
});

it('scrolled with prefix, suffix, clear button', async () => {
const prefix = document.createElement('span');
prefix.setAttribute('slot', 'prefix');
prefix.textContent = '$';
element.appendChild(prefix);

const suffix = document.createElement('span');
suffix.setAttribute('slot', 'suffix');
suffix.textContent = '$';
element.appendChild(suffix);

element.clearButtonVisible = true;
element.style.height = '70px';
element.value = 'a\nb\nc\nd\ne';
element.focus();
await visualDiff(div, 'scrolled-with-prefix-suffix-clear-button');
});

it('error message', async () => {
element.label = 'Label';
element.errorMessage = 'This field is required';
Expand Down
14 changes: 12 additions & 2 deletions packages/text-area/theme/lumo/vaadin-text-area-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ const textArea = css`
--_lumo-text-field-overflow-mask-image: none;
}
/* Vertically align icon prefix/suffix with the first line of text */
[part='input-field'] ::slotted(vaadin-icon) {
/* Use sticky positioning to keep prefix/suffix/clear button visible when scrolling textarea container */
[part='input-field'] ::slotted([slot$='fix']),
[part='clear-button'] {
position: sticky;
top: 0;
align-self: flex-start;
}
/* Vertically align icon prefix/suffix/clear button with the first line of text */
[part='input-field'] ::slotted(vaadin-icon[slot$='fix']),
[part='clear-button'] {
top: calc((var(--lumo-icon-size-m) - 1em * var(--lumo-line-height-s)) / -2);
margin-top: calc((var(--lumo-icon-size-m) - 1em * var(--lumo-line-height-s)) / -2);
}
`;
Expand Down
8 changes: 8 additions & 0 deletions packages/text-area/theme/material/vaadin-text-area-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const textArea = css`
[part='input-field']::after {
bottom: calc(var(--_text-area-vertical-scroll-position) * -1);
}
/* Use sticky positioning to keep prefix/suffix/clear button visible when scrolling textarea container */
[part='input-field'] ::slotted([slot$='fix']),
[part='clear-button'] {
position: sticky;
top: 0;
align-self: flex-start;
}
`;

registerStyles('vaadin-text-area', [inputFieldShared, textArea], { moduleId: 'material-text-area' });

0 comments on commit 21ab55d

Please sign in to comment.