Skip to content

Commit

Permalink
fix: select
Browse files Browse the repository at this point in the history
  • Loading branch information
XboxYan committed May 5, 2023
1 parent f6812e3 commit 81a473a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions components/select/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import "../button/index.js";
import "../icon/index.js";

export default class Select extends Base {
#valueEl;
#slots;
#popoverEl;
#buttonEl;
Expand All @@ -29,7 +28,6 @@ export default class Select extends Base {
</div>
</xy-popover>
`;
this.#valueEl = this.querySelector("[behavior='selected-value']") || this.querySelector("[slot='button']") || this.shadowRoot.querySelector("[behavior='selected-value']");
this.#popoverEl = this.shadowRoot.getElementById("popover");
this.#buttonEl = this.shadowRoot.getElementById("button");
}
Expand All @@ -39,6 +37,10 @@ export default class Select extends Base {
button.focus(options);
}

get #valueEl() {
return this.querySelector("[behavior='selected-value']") || this.querySelector("[slot='button']") || this.shadowRoot.querySelector("[behavior='selected-value']");
}

get value() {
return this.#valueEl.getAttribute("value");
}
Expand Down Expand Up @@ -88,7 +90,6 @@ export default class Select extends Base {
}

connectedCallback() {
this.#valueEl = this.querySelector("[behavior='selected-value']") || this.querySelector("[slot='button']") || this.shadowRoot.querySelector("[behavior='selected-value']");
this.#slots = this.shadowRoot.getElementById("slot");
this.#slots.addEventListener("slotchange", () => {
if (this.#popoverEl.parentNode === document.body) {
Expand Down
6 changes: 3 additions & 3 deletions docs/components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ select.removeAttribute('disabled');
还可以指定选中文本显示的节点,通过`behavior="selected-value"`指定(没有该属性时默认渲染到`slot="button"`本身)

<style scoped>
.custom-button::part(button):active{
.custom-select-button::part(button):active{
background: transparent;
}
.custom-button label{
.custom-select-button label{
position: absolute;
font-size: 12px;
background: var(--primary-bg);
Expand All @@ -229,7 +229,7 @@ select.removeAttribute('disabled');

<div class="wrap">
<xy-select>
<xy-button class="custom-button" slot="button">
<xy-button class="custom-select-button" slot="button">
<label>地区</label>
<span behavior="selected-value"></span>
</xy-button>
Expand Down

0 comments on commit 81a473a

Please sign in to comment.