+
Skip to content
Open
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
33 changes: 30 additions & 3 deletions src/ui/c-input-text/c-input-text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,41 @@ watch(
{ immediate: true },
);

/**
* Checks if the given HTMLElement overflows
* copied from stackoverflow: https://stackoverflow.com/questions/143815/determine-if-an-html-elements-content-overflows
* @param el The HTMLElement to check
*/
function checkOverflow(el: HTMLElement) {
const curOverflow = el.style.overflow;
if (!curOverflow || curOverflow === 'visible') {
el.style.overflow = 'hidden';
}

const isOverflowing = el.clientWidth < el.scrollWidth || el.clientHeight < el.scrollHeight;

el.style.overflow = curOverflow;

return isOverflowing;
}

function resizeTextarea() {
if (!textareaRef.value || !inputWrapperRef.value) {
if (textareaRef.value === undefined) {
return; // cannot chnge textarea if element is not available
}

if (!multiline) {
return; // textarea wont be displayed if multiline === false
}

if (!checkOverflow(textareaRef.value)) {
return;
}

const scrollHeight = textareaRef.value.scrollHeight + 2;
const textAreaElement = textareaRef.value!;

inputWrapperRef.value.style.height = `${scrollHeight}px`;
const scrollHeight = textAreaElement.scrollHeight + 2;
textAreaElement.style.height = `${scrollHeight}px`;
}

const htmlInputType = computed(() => {
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载