Add caret position function to text area and fix issue with design transitions and custom styles

This commit is contained in:
Andrew Kingston 2021-04-19 15:07:25 +01:00
parent 36b1cd75fd
commit 1bc678ad9e
3 changed files with 18 additions and 9 deletions

View File

@ -7,8 +7,13 @@
export let disabled = false export let disabled = false
export let error = null export let error = null
export let id = null export let id = null
export const getCaretPosition = () => ({
start: textarea.selectionStart,
end: textarea.selectionEnd,
})
let focus = false let focus = false
let textarea
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = event => { const onChange = event => {
dispatch("change", event.target.value) dispatch("change", event.target.value)
@ -30,6 +35,7 @@
</svg> </svg>
{/if} {/if}
<textarea <textarea
bind:this={textarea}
placeholder={placeholder || ''} placeholder={placeholder || ''}
class="spectrum-Textfield-input" class="spectrum-Textfield-input"
{disabled} {disabled}

View File

@ -9,6 +9,7 @@
export let placeholder = null export let placeholder = null
export let disabled = false export let disabled = false
export let error = null export let error = null
export let getCaretPosition = null
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const onChange = e => { const onChange = e => {
@ -18,5 +19,11 @@
</script> </script>
<Field {label} {labelPosition} {disabled} {error}> <Field {label} {labelPosition} {disabled} {error}>
<TextArea {error} {disabled} {value} {placeholder} on:change={onChange} /> <TextArea
bind:getCaretPosition
{error}
{disabled}
{value}
{placeholder}
on:change={onChange} />
</Field> </Field>

View File

@ -63,7 +63,7 @@
<div class="custom-styles"> <div class="custom-styles">
<TextArea <TextArea
value={componentInstance._styles.custom} value={componentInstance._styles.custom}
on:change={event => onCustomStyleChanged(event.target.value)} on:change={event => onCustomStyleChanged(event.detail)}
placeholder="Enter some CSS..." /> placeholder="Enter some CSS..." />
</div> </div>
</DetailSummary> </DetailSummary>
@ -79,15 +79,11 @@
<div class="transitions"> <div class="transitions">
<Select <Select
value={componentInstance._transition} value={componentInstance._transition}
on:change={event => onUpdateTransition(event.target.value)} on:change={event => onUpdateTransition(event.detail)}
name="transition" name="transition"
label="Transition" label="Transition"
secondary options={transitions}
thin> getOptionLabel={capitalize} />
{#each transitions as transition}
<option value={transition}>{capitalize(transition)}</option>
{/each}
</Select>
</div> </div>
{/if} {/if}
</div> </div>