Sfoglia il codice sorgente

Fix x-disclosure when used with x-collapse transitioning in on the page load instead of showing up instantly

Caleb Porzio 1 anno fa
parent
commit
1212d22c42
1 ha cambiato i file con 10 aggiunte e 5 eliminazioni
  1. 10 5
      packages/ui/src/disclosure.js

+ 10 - 5
packages/ui/src/disclosure.js

@@ -25,12 +25,13 @@ function handleRoot(el, Alpine) {
         'x-modelable': '__isOpen',
         'x-data'() {
             return {
-                init() {
-                    queueMicrotask(() => {
-                         let defaultIsOpen = Boolean(Alpine.bound(this.$el, 'default-open', false))
+                // The panel will call this...
+                // We can't do this inside a microtask in x-init because, when default-open is set to "true",
+                // It will cause the panel to transition in for the first time, instead of showing instantly...
+                __determineDefaultOpenState() {
+                    let defaultIsOpen = Boolean(Alpine.bound(this.$el, 'default-open', false))
 
-                         if (defaultIsOpen) this.__isOpen = defaultIsOpen
-                    })
+                    if (defaultIsOpen) this.__isOpen = defaultIsOpen
                 },
                 __isOpen: false,
                 __close() {
@@ -70,7 +71,11 @@ function handleButton(el, Alpine) {
 
 function handlePanel(el, Alpine) {
     Alpine.bind(el, {
+        'x-init'() {
+            this.$data.__determineDefaultOpenState()
+        },
         'x-show'() {
+           console.log('process show')
             return this.$data.__isOpen
         },
         ':id'() {