Skip to content

Commit

Permalink
feat: allow shrinking text area to single row (#8168)
Browse files Browse the repository at this point in the history
* feat: allow using single row for text area

* update material theme to align single row textarea with other field components

* update screenshots

* update docs
  • Loading branch information
sissbruecker authored Jan 7, 2025
1 parent 9548842 commit dc2102c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/text-area/src/vaadin-text-area-mixin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export declare class TextAreaMixinClass {
pattern: string;

/**
* Minimum number of rows to show. Default is two rows, which is also the minimum value.
* Minimum number of rows to show. Default is two rows.
*
* When using a custom slotted textarea, the minimum number of rows are not applied for backwards compatibility.
*
Expand Down
8 changes: 4 additions & 4 deletions packages/text-area/src/vaadin-text-area-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const TextAreaMixin = (superClass) =>
},

/**
* Minimum number of rows to show. Default is two rows, which is also the minimum value.
* Minimum number of rows to show. Default is two rows.
*
* When using a custom slotted textarea, the minimum number of rows are not applied for backwards compatibility.
*
Expand Down Expand Up @@ -219,7 +219,7 @@ export const TextAreaMixin = (superClass) =>
// Do not override this on custom slotted textarea as number of rows may
// have been configured there.
if (this.inputElement === this.__textAreaController.defaultNode) {
this.inputElement.rows = Math.max(minRows, 2);
this.inputElement.rows = Math.max(minRows, 1);
}
}

Expand Down Expand Up @@ -257,8 +257,8 @@ export const TextAreaMixin = (superClass) =>
* @private
*/
__minRowsChanged(minRows) {
if (minRows < 2) {
console.warn('<vaadin-text-area> minRows must be at least 2.');
if (minRows < 1) {
console.warn('<vaadin-text-area> minRows must be at least 1.');
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/text-area/test/text-area.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,18 @@ describe('text-area', () => {
expect(textArea.clientHeight).to.equal(lineHeight * 4);
});

it('should not be possible to set min-height to less than two rows', async () => {
it('should be possible to set min-height to a single row', async () => {
textArea.minRows = 1;
await nextUpdate(textArea);

expect(textArea.clientHeight).to.closeTo(lineHeight * 2, 1);
expect(textArea.clientHeight).to.closeTo(lineHeight, 1);
});

it('should log warning when setting minRows to less than two rows', async () => {
textArea.minRows = 1;
it('should log warning when setting minRows to less than one row', async () => {
textArea.minRows = 0;
await nextUpdate(textArea);

expect(console.warn).to.be.calledWith('<vaadin-text-area> minRows must be at least 2.');
expect(console.warn).to.be.calledWith('<vaadin-text-area> minRows must be at least 1.');
});

it('should not log warning when setting minRows to two rows or more', async () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 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 @@ -130,4 +130,12 @@ describe('text-area', () => {
element.maxRows = 4;
await visualDiff(div, 'max-rows');
});

it('single-row', async () => {
element.minRows = 1;
element.value = 'value';
element.clearButtonVisible = true;

await visualDiff(div, 'single-row');
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 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 @@ -132,4 +132,12 @@ describe('text-area', () => {
element.maxRows = 4;
await visualDiff(div, 'max-rows');
});

it('single-row', async () => {
element.minRows = 1;
element.value = 'value';
element.clearButtonVisible = true;

await visualDiff(div, 'single-row');
});
});
5 changes: 4 additions & 1 deletion packages/text-area/theme/lumo/vaadin-text-area-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const textArea = css`
[part='input-field'] ::slotted(textarea) {
height: auto;
box-sizing: border-box;
min-height: 0;
}
[part='input-field'] {
Expand Down Expand Up @@ -64,11 +65,13 @@ const textArea = css`
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'] {
/* Vertically align icon prefix/suffix/clear button with the first line of text */
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);
/* Reduce effective height to match line height of native textarea, so icons don't increase component size when using single row */
margin-bottom: calc((var(--lumo-icon-size-m) - 1em * var(--lumo-line-height-s)) / -2);
}
`;

Expand Down

0 comments on commit dc2102c

Please sign in to comment.