Add readonly prop to combobox

This commit is contained in:
Andrew Kingston 2021-11-23 16:40:31 +00:00
parent 5f2f01851b
commit 5ecd09b39e
3 changed files with 8 additions and 4 deletions

View File

@ -6,6 +6,7 @@
export let value = null
export let label = undefined
export let disabled = false
export let readonly = false
export let labelPosition = "above"
export let error = null
export let placeholder = "Choose an option or type"
@ -33,6 +34,7 @@
{value}
{options}
{placeholder}
{readonly}
{getOptionLabel}
{getOptionValue}
on:change={onChange}

View File

@ -9,6 +9,7 @@
export let id = null
export let placeholder = "Choose an option or type"
export let disabled = false
export let readonly = false
export let error = null
export let options = []
export let getOptionLabel = option => option
@ -73,6 +74,7 @@
value={value || ""}
placeholder={placeholder || ""}
{disabled}
{readonly}
class="spectrum-Textfield-input spectrum-InputGroup-input"
/>
</div>

View File

@ -16,15 +16,15 @@
const dispatch = createEventDispatcher()
let focus = false
const updateValue = value => {
const updateValue = newValue => {
if (readonly) {
return
}
if (type === "number") {
const float = parseFloat(value)
value = isNaN(float) ? null : float
const float = parseFloat(newValue)
newValue = isNaN(float) ? null : float
}
dispatch("change", value)
dispatch("change", newValue)
}
const onFocus = () => {