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

fix: LEAP-878: Fix shrinking textarea on edit #5665

Merged
merged 8 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 4 additions & 4 deletions web/dist/apps/labelstudio/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "Merge branch 'develop' into 'fb-HUMSIG-37-visuals'",
"commit": "309851f803a1995c36b11f416f80cff709b6be2f",
"date": "2024-04-04T16:34:09.000Z",
"branch": "fb-HUMSIG-37-visuals"
"message": "Merge branch 'develop' into 'fb-leap-878/textarea-height'",
"commit": "2e2ecfe86d4c4ce6fa9c4f3802594654bb9907b2",
"date": "2024-04-05T15:43:42.000Z",
"branch": "fb-leap-878/textarea-height"
}
8 changes: 4 additions & 4 deletions web/dist/libs/datamanager/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "Merge branch 'develop' into 'fb-HUMSIG-37-visuals'",
"commit": "309851f803a1995c36b11f416f80cff709b6be2f",
"date": "2024-04-04T16:34:09.000Z",
"branch": "fb-HUMSIG-37-visuals"
"message": "Merge branch 'develop' into 'fb-leap-878/textarea-height'",
"commit": "2e2ecfe86d4c4ce6fa9c4f3802594654bb9907b2",
"date": "2024-04-05T15:43:42.000Z",
"branch": "fb-leap-878/textarea-height"
}
2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/dist/libs/editor/main.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions web/dist/libs/editor/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "Merge branch 'develop' into 'fb-HUMSIG-37-visuals'",
"commit": "309851f803a1995c36b11f416f80cff709b6be2f",
"date": "2024-04-04T16:34:09.000Z",
"branch": "fb-HUMSIG-37-visuals"
"message": "Merge branch 'develop' into 'fb-leap-878/textarea-height'",
"commit": "2e2ecfe86d4c4ce6fa9c4f3802594654bb9907b2",
"date": "2024-04-05T15:43:42.000Z",
"branch": "fb-leap-878/textarea-height"
}
11 changes: 8 additions & 3 deletions web/libs/editor/src/components/HtxTextBox/HtxTextBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import throttle from 'lodash.throttle';
import { FF_DEV_1566, isFF } from '../../utils/feature-flags';

const { Paragraph } = Typography;
// used for correct auto-height calculation
const BORDER_WIDTH = 1;

export class HtxTextBox extends React.Component {
state = {
Expand Down Expand Up @@ -85,9 +87,12 @@ export class HtxTextBox extends React.Component {
};

updateHeight = throttle(() => {
const height = this.inputRef.current?.scrollHeight || 0;
// very important to add borders to the height, otherwise input will be shrinking on every recalc
const scrollHeight = this.inputRef.current?.scrollHeight ?? 0;
const height = scrollHeight + BORDER_WIDTH * 2;

if (height && height !== this.state.height) {
// initially scrollHeight can be 0, so we won't change height
if (scrollHeight && height !== this.state.height) {
this.setState({ height });
}
}, 100);
Expand All @@ -114,7 +119,7 @@ export class HtxTextBox extends React.Component {
const inputProps = {
name,
className: 'ant-input ' + styles.input,
style: height ? { height } : null,
style: height ? { height, borderWidth: BORDER_WIDTH } : null,
autoFocus: true,
ref: this.inputRef,
value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.input {
width: 100%;
padding: 0.4em 1em;
border-width: 1px;
display: block;
}

Expand All @@ -15,7 +16,8 @@

.delete {
color: #1890ff;
padding-top: 0.5em;
// Typography.Paragraph has margin-bottom: 1em, so we have to compensate it to have icon in the middle
margin-top: -1em;
padding-left: 1em;
line-height: 1.8em;
}