diff --git a/src/collapse/index.js b/src/collapse/index.js index 38cda0c..62cff09 100644 --- a/src/collapse/index.js +++ b/src/collapse/index.js @@ -4,7 +4,7 @@ * @date 2023/03/26 16:14:10 */ -import { css, html, Component } from '@bd/core' +import { css, html, Component, styleMap, nextTick } from '@bd/core' import '../icon/index.js' class Collapse extends Component { @@ -60,6 +60,7 @@ class Collapse extends Component { mounted() { this.$children = Array.from(this.children) this.updateView() + this.$on('updateValue', e => this.updateValue(e.name)) } } class CollapseItem extends Component { @@ -69,6 +70,7 @@ class CollapseItem extends Component { disabled: false } _show = false + contentHeight = 0 static styles = [ css` :host { @@ -117,37 +119,40 @@ class CollapseItem extends Component { if (this.disabled) { return } - this.parentNode.updateValue(this.name) + this.$emit('updateValue', { name: this.name }) } get show() { return this._show } set show(val) { - const { content, wrapper, icon } = this.$refs - if (!wrapper) { - this.onMounted = () => (this.show = val) - return - } - if (val) { - wrapper.style.height = content.offsetHeight + 'px' - icon.style.transform = 'rotate(90deg)' - } else { - wrapper.style.height = 0 - icon.style.transform = 'rotate(0deg)' - } this._show = val + this.contentHeight = this.$refs.content?.offsetHeight || 0 + this.$requestUpdate() } mounted() { - this.onMounted && this.onMounted() + nextTick(() => { + this.contentHeight = this.$refs.content.offsetHeight + this.$requestUpdate() + }) } render() { return html`