Skip to content

Commit

Permalink
fix: select box bug
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed Feb 25, 2021
1 parent 3599a6c commit ea7f10a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
19 changes: 8 additions & 11 deletions components/select/src/MultipleSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
let clientHeight = 0;
onMount(() => {
const onClick = () => {
show = false;
const onHide = (e: Event) => {
if (!ref!.contains(e.target as Node)) show = false;
};
window.addEventListener("click", onClick);
window.addEventListener("click", onHide);
return () => {
window.removeEventListener("click", onClick);
window.removeEventListener("click", onHide);
};
});
Expand All @@ -54,7 +54,7 @@
}
value = [...value];
input!.focus();
dispatch("change", { value });
dispatch("change", value);
}
};
Expand All @@ -63,16 +63,13 @@
if (val) {
e.stopPropagation();
value = value.filter((v) => v !== val);
dispatch("change", { value });
dispatch("change", value);
}
};
</script>

<div class="responsive-ui-select--multiple {className}" bind:this={ref}>
<div
class="responsive-ui-select-input"
on:click|stopPropagation={() => (show = true)}
>
<div class="responsive-ui-select-input" on:click={() => (show = true)}>
<input {name} type="hidden" value={value.join(",")} />
<span class="responsive-ui-select__tags" on:click={onRemove}>
{#each value as item}
Expand All @@ -98,7 +95,7 @@
</div>
<div
class="responsive-ui-select__dropdown"
on:click|stopPropagation={onSelect}
on:click={onSelect}
style={`height:${show ? clientHeight : 0}px;max-height:${maxHeight}px;`}
>
<div bind:clientHeight style="padding:10px 0">
Expand Down
2 changes: 1 addition & 1 deletion components/select/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SelectProps {
ref?: null | HTMLSelectElement;
name?: string;
size?: number;
multiple?: false;
multiple?: boolean;
value?: string | string[];
disabled?: boolean;
readonly?: boolean;
Expand Down
17 changes: 17 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,23 @@
<button on:click={() => (openRightDock = true)}>open right dock</button>
</div>

<Select
multiple={true}
size={5}
value={["e"]}
on:change={console.log}
options={[
{ label: "CC", value: "cc" },
{ label: "Option A", value: "a", disabled: true },
{ label: "Z", value: "z" },
{ label: "Option B", value: "b" },
{ label: "Option C", value: "c" },
{ label: "Option D", value: "d" },
{ label: "Option E", value: "e" },
{ label: "Option F", value: "f" },
{ label: "Option G", value: "g" },
]}
/>
<Select
multiple={true}
size={5}
Expand Down

0 comments on commit ea7f10a

Please sign in to comment.