Skip to content

Commit 1540e4b

Browse files
committed
♻ Refactored Multi Select to use new position class
1 parent a163621 commit 1540e4b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/framework/components/multi-select/multi-select.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
}
154154

155155
multiselect-options {
156-
position: absolute;
157-
top: calc(100% + 0.25rem);
156+
position: fixed;
157+
top: 0;
158158
left: 0;
159159
width: 100%;
160160
background-color: var(--white);

src/framework/components/multi-select/multi-select.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import soundscape from "~brixi/controllers/soundscape";
77
import Checkbox from "~brixi/components/checkbox/checkbox";
88
import { UUID } from "@codewithkyle/uuid";
99
import Fuse from "fuse.js";
10+
import pos from "~brixi/controllers/pos";
1011

1112
export type MultiSelectOption = {
1213
label: string;
@@ -357,6 +358,12 @@ export default class MultiSelect extends SuperComponent<IMultiSelect> {
357358
render() {
358359
const id = `${this.model.name}-${this.model.label.replace(/\s+/g, "-").trim()}`;
359360
this.id = id;
361+
this.setAttribute("state", this.state);
362+
this.className = `multi-select js-input ${this.model.class}`;
363+
this.style.cssText = this.model.css;
364+
Object.keys(this.model.attributes).map((key) => {
365+
this.setAttribute(key, `${this.model.attributes[key]}`);
366+
});
360367
const selected = this.calcSelected();
361368
const options = this.filterOptions();
362369
this.tabIndex = 0;
@@ -386,14 +393,13 @@ export default class MultiSelect extends SuperComponent<IMultiSelect> {
386393
</div>
387394
</multiselect-options>
388395
`;
389-
this.setAttribute("state", this.state);
390-
this.className = `multi-select js-input ${this.model.class}`;
391-
this.style.cssText = this.model.css;
392-
Object.keys(this.model.attributes).map((key) => {
393-
this.setAttribute(key, `${this.model.attributes[key]}`);
394-
});
395396
setTimeout(() => {
396397
render(view, this);
398+
const options = this.querySelector("multiselect-options") as HTMLElement;
399+
if (options) {
400+
options.style.width = `${this.scrollWidth}px`;
401+
pos.positionElementToElement(options, this, 8);
402+
}
397403
}, 80);
398404
}
399405
}

0 commit comments

Comments
 (0)