Skip to content

Commit

Permalink
fix: slot
Browse files Browse the repository at this point in the history
  • Loading branch information
XboxYan committed May 8, 2023
1 parent 94bc44e commit 8714b71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/select/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Base from "../xy-base.js";
import style from "./index.css?inline" assert { type: "css" };
import "../popover/index.js";
import "../button/index.js";
import "../popover/index.js";
import "../icon/index.js";

export default class Select extends Base {
Expand Down
10 changes: 6 additions & 4 deletions components/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@
--tips-color: #fff;
}

xy-popover:not(:defined){
position: absolute;
visibility: hidden;
}

html:has(xy-dialog[open]){
overflow: hidden;
}

xy-select:not(:defined) xy-option,
xy-popover:not(:defined){
position: absolute;
visibility: hidden;
}

xy-select xy-button[slot="button"]::part(button)::after{
content: '';
width: 1em;
Expand Down
22 changes: 12 additions & 10 deletions components/xy-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class Base extends HTMLElement {
super();
}

#mounted = [];
#mounted = false;

adoptedStyle (style, dom) {
let styleSheet = style
Expand Down Expand Up @@ -37,17 +37,19 @@ export default class Base extends HTMLElement {
}
if (!this.slots.length) return
return new Promise((resolve) => {
if (this.#mounted.length === this.slots.length) {
if (this.#mounted) {
resolve()
} else {
this.slots.forEach((el,i) => el.addEventListener("slotchange", () => {
if (!this.#mounted[i]) {
this.#mounted[i] = true
}
if (this.#mounted.length === this.slots.length) {
setTimeout(resolve, 200);
}
}))
Promise.all(this.slots.map(el => new Promise((_resolve, reject) => {
el.addEventListener("slotchange", () => {
_resolve()
})
})))
.then(() =>{
console.log('slot加载完成')
this.#mounted = true
resolve()
})
}
})
}
Expand Down

0 comments on commit 8714b71

Please sign in to comment.