Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
fix: input resize bug (#472)
Browse files Browse the repository at this point in the history
* fix: input resize bug
* fix: add placeholder text
  • Loading branch information
andrewrisse authored May 9, 2024
1 parent 21be2a1 commit da7e377
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/leapfrogai_ui/src/lib/components/LFTextArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ The invalid prop can still be passed to this component to validate for other con
let lengthInvalidText = 'Character limit reached';
$: limitReached = $value.length === Number(env.PUBLIC_MESSAGE_LENGTH_LIMIT);
let inputHeight = '';
function resizeTextArea() {
if (ref) {
ref.style.height = '1px';
Expand All @@ -92,8 +91,6 @@ The invalid prop can still be passed to this component to validate for other con
}
onMount(() => {
const style = getComputedStyle(document.documentElement);
inputHeight = style.getPropertyValue('--message-input-height').trim();
resizeTextArea();
});
</script>
Expand Down Expand Up @@ -145,9 +142,9 @@ The invalid prop can still be passed to this component to validate for other con
style="--maxRows:{maxRows};"
maxlength={maxCount + 1 ?? undefined}
{...$$restProps}
on:change
on:input={resizeTextArea}
on:keyup={resizeTextArea}
on:keydown={(e) => {
resizeTextArea();
// Allow user to type up to maxCount, but only show error once trying to add more
// characters after hitting this limit

Expand All @@ -169,12 +166,11 @@ The invalid prop can still be passed to this component to validate for other con
showLengthError = true; // throw error
} else {
if (e.key === 'Enter' && !e.shiftKey && ref) {
ref.style.height = inputHeight; // reset input size if there were multiple lines
resizeTextArea();
onSubmit(e);
}
}
}}
on:keyup
on:focus
on:blur
on:paste
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
value={input}
{onSubmit}
ariaLabel="message input"
placeholder="Type your message here..."
bind:showLengthError={lengthInvalid}
/>

Expand Down

0 comments on commit da7e377

Please sign in to comment.