Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds auto resize feature to textarea #10786

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions packages/ui/src/fields/Textarea/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,16 @@ export const TextareaInput: React.FC<TextAreaInputProps> = (props) => {
/>
{BeforeInput}
<label className="textarea-outer" htmlFor={`field-${path.replace(/\./g, '__')}`}>
<div className="textarea-inner">
<div className="textarea-clone" data-value={value || placeholder || ''} />
<textarea
className="textarea-element"
data-rtl={rtl}
disabled={readOnly}
id={`field-${path.replace(/\./g, '__')}`}
name={path}
onChange={onChange}
placeholder={getTranslation(placeholder, i18n)}
rows={rows}
value={value || ''}
/>
</div>
<textarea
data-rtl={rtl}
disabled={readOnly}
id={`field-${path.replace(/\./g, '__')}`}
name={path}
onChange={onChange}
placeholder={getTranslation(placeholder, i18n)}
rows={rows}
value={value || ''}
/>
</label>
{AfterInput}
<RenderCustomComponent
Expand Down
84 changes: 6 additions & 78 deletions packages/ui/src/fields/Textarea/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
display: flex;
flex-direction: column;

.textarea-outer {
textarea {
@include formInput();
display: flex;
field-sizing: content;
overflow-y: auto;
resize: vertical;
min-height: base(3);
height: 100%;

// Scrollbar for giant content
max-height: calc(100vh - $top-header-offset - calc(#{base(5)}));
overflow: hidden;

@include mid-break {
max-height: 60vh;
}
display: flex;
}

&.read-only {
Expand All @@ -28,78 +22,12 @@
}
}

// This element takes exactly the same dimensions as the clone
.textarea-inner {
display: block;
position: relative;
line-height: inherit;
flex-grow: 1;
background: none;
outline: none;
}

// Unstyle the textarea, the border is rendered on .textarea-outer
.textarea-element {
position: relative;
z-index: 1;
width: 100%;
height: 100%;
border: inherit;
padding: inherit;
font: inherit;
line-height: inherit;
color: inherit;
background: none;
overflow: auto;
resize: none;
outline: none;
text-transform: inherit;

&::-webkit-scrollbar {
display: none;
}
&[data-rtl='true'] {
direction: rtl;
}
}

// Clone of textarea with same height
.textarea-clone {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
white-space: pre-wrap;
overflow-wrap: break-word;
visibility: hidden;
z-index: 0;
line-height: inherit;
}

.textarea-clone::before {
content: attr(data-value) ' ';
visibility: hidden;
opacity: 0;
white-space: pre-wrap;
overflow-wrap: break-word;
}

.textarea-clone::after {
content: attr(data-after);
opacity: 0.5;
}

@include mid-break {
padding: 0;
}
}

html[data-theme='light'] {
.field-type.textarea {
&.error {
.textarea-outer {
textarea {
@include lightInputError;
}
}
Expand All @@ -109,7 +37,7 @@
html[data-theme='dark'] {
.field-type.textarea {
&.error {
.textarea-outer {
textarea {
@include darkInputError;
}
}
Expand Down