Skip to content
Open
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
5 changes: 5 additions & 0 deletions js/utils/calcTextareaHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ function calcTextareaHeight(
minRows: LimitType = 1,
maxRows: LimitType = null,
): CalculateStyleType {
// 验证元素有效性 - 修复 Bug #6028
if (!targetElement || !targetElement.isConnected) {
return { height: 'auto' };
}

if (!hiddenTextarea) {
hiddenTextarea = document.createElement('textarea');
document.body.appendChild(hiddenTextarea);
Expand Down
30 changes: 26 additions & 4 deletions js/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,49 @@
};
}

const style = window.getComputedStyle(targetElement);
// 验证元素有效性 - 修复 Bug #6028
if (!targetElement
|| !(targetElement instanceof Element)
|| !targetElement.isConnected
|| !document.contains(targetElement)) {
return {
paddingSize: 0,
borderSize: 0,
boxSizing: 'border-box',
sizingStyle: '',
};
Comment on lines +249 to +254
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

提出來一個變量

}

try {
const style = window.getComputedStyle(targetElement);

const boxSizing = style.getPropertyValue('box-sizing')

Check failure on line 260 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2
|| style.getPropertyValue('-moz-box-sizing')
|| style.getPropertyValue('-webkit-box-sizing');

const paddingSize = (

Check failure on line 264 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2
parseFloat(style.getPropertyValue('padding-bottom'))

Check failure on line 265 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 4
+ parseFloat(style.getPropertyValue('padding-top'))
);

Check failure on line 267 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2

const borderSize = (

Check failure on line 269 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2
parseFloat(style.getPropertyValue('border-bottom-width'))

Check failure on line 270 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 4
+ parseFloat(style.getPropertyValue('border-top-width'))
);

Check failure on line 272 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2

const sizingStyle = DOM_STYLE_PROPS

Check failure on line 274 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 2
.map((name) => `${name}:${style.getPropertyValue(name)}`)

Check failure on line 275 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 4
.join(';');

Check failure on line 276 in js/utils/helper.ts

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 4

return {
paddingSize, borderSize, boxSizing, sizingStyle,
};
return {
paddingSize, borderSize, boxSizing, sizingStyle,
};
} catch (error) {
return {
paddingSize: 0,
borderSize: 0,
boxSizing: 'border-box',
sizingStyle: '',
};
}
}