Skip to content

Commit

Permalink
[bulk-textarea] UIK-3152 rows count changes after clearAll by button
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabrower committed Jan 14, 2025
1 parent 41952cc commit ae033d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion semcore/bulk-textarea/src/BulkTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BulkTextareaRoot extends Component<
readonly,
pasteProps,
} = this.asProps;
const { errors, errorIndex, showErrors, lastError } = this.state;
const { errors, errorIndex, showErrors, lastError, rowsCount } = this.state;

return {
value,
Expand All @@ -90,6 +90,7 @@ class BulkTextareaRoot extends Component<
placeholder,
lastError,
pasteProps,
rowsCount,
onChangeRowsCount: this.handleChangeRowsCount,
onEnterNextRow: () => {
if (validateOn?.includes('enterNextRow')) {
Expand Down
16 changes: 8 additions & 8 deletions semcore/bulk-textarea/src/components/InputField/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class InputField extends Component<InputFieldProps, {}, State, typeof InputField
minRows: 2,
maxRows: 10,
defaultShowErrors: false,
defaultRowsCount: 0,
};

delimiter = '\n';
Expand All @@ -55,7 +56,6 @@ class InputField extends Component<InputFieldProps, {}, State, typeof InputField
isFocusing = false;

rowsCountTimeout = 0;
rowsCount = 0;

state = {
visibleErrorPopper: false,
Expand Down Expand Up @@ -83,6 +83,7 @@ class InputField extends Component<InputFieldProps, {}, State, typeof InputField
uncontrolledProps() {
return {
value: null,
rowsCount: null,
};
}

Expand Down Expand Up @@ -685,8 +686,8 @@ class InputField extends Component<InputFieldProps, {}, State, typeof InputField
}

this.rowsCountTimeout = window.setTimeout(() => {
let rowsCount = 0;
const { ofRows } = this.asProps;
let rows = 0;
const { ofRows, rowsCount } = this.asProps;

this.textarea.childNodes.forEach((node, index) => {
if (node instanceof HTMLParagraphElement) {
Expand All @@ -696,18 +697,17 @@ class InputField extends Component<InputFieldProps, {}, State, typeof InputField
node.textContent !== this.getEmptyParagraph().textContent &&
node.textContent !== ''
) {
rowsCount++;
rows++;

if (rowsCount > ofRows) {
if (rows > ofRows) {
node.dataset.overMaxRows = 'true';
}
}
}
});

if (this.rowsCount !== rowsCount) {
this.rowsCount = rowsCount;
this.asProps.onChangeRowsCount(rowsCount);
if (rowsCount !== rows) {
this.asProps.onChangeRowsCount(rows);
}
}, 100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export type InputFieldProps = {
*/
currentRowIndex: number;

/**
* Internal
*/
rowsCount: number;
/**
* Internal
*/
Expand Down

0 comments on commit ae033d3

Please sign in to comment.