Skip to content

Commit

Permalink
Remove placeholder when input value is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinheldy committed Aug 28, 2023
1 parent 310f8d1 commit 12caaa9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib/use-bootstrap-tag.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
let tagActiveIndex = -1
$: values = value.split(options.separator).filter((i) => i !== '')
$: placeholder = values.length ? '' : inputElement.placeholder
$: if (textElement) {
const canvas = document.createElement('canvas')
const context = canvas.getContext('2d')
if (context) {
context.font = getComputedStyle(textElement).font
textWidth = context.measureText(
text || textElement.placeholder || ''
).width
textWidth = context.measureText(text || placeholder).width
}
canvas.remove()
}
Expand Down Expand Up @@ -238,7 +237,7 @@
{/each}
<input
type="text"
placeholder={inputElement.placeholder}
{placeholder}
bind:this={textElement}
bind:value={text}
style:width={`${textWidth}px`}
Expand Down

0 comments on commit 12caaa9

Please sign in to comment.