-
Notifications
You must be signed in to change notification settings - Fork 7
refactor(bubble)!: Make collapsible-text fold state reactively #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughReplaced the defaultOpen prop with a model-backed open state. Added internal openInternal ref and an open computed that proxies to model.open when available. Updated template bindings and click handler to use open. Removed all references to opened and defaultOpen. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant P as Parent
participant C as CollapsibleText
participant M as model.open (optional)
participant L as openInternal (local)
Note over C: Component mounts
alt Model provided
P->>C: Bind v-model:open
C->>M: Read model.open via computed getter
P->>C: User click toggles
C->>M: Setter updates model.open
M-->>P: Parent reacts to change
else No model provided
C->>L: Read/write openInternal via computed
P->>C: User click toggles
C->>L: Setter updates openInternal
end
C->>C: UI reflects `open` (icon rotate, content visibility)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/components/src/bubble/renderers/collapsible-text.vue (2)
5-9: Consider simplifying the model pattern.The current pattern uses
defineModel<{ open?: boolean }>()with a default empty object, which requires additional logic to check ifmodel.value.openis set. This adds complexity compared to the more idiomatic Vue 3 approach of usingdefineModel<boolean>('open', { default: false })withv-model:open.If you prefer the current object-based model pattern, consider this alternative that's clearer:
-const model = defineModel<{ open?: boolean }>({ - default() { - return {} - }, -}) +const model = defineModel<boolean>('open')Then simplify the state management:
const openInternal = ref(false) -const modelOpenIsSet = computed<boolean>(() => model.value && model.value.open !== void 0) const open = computed<boolean>({ get() { - return modelOpenIsSet.value ? model.value.open! : openInternal.value + return model.value ?? openInternal.value }, set(value) { - if (modelOpenIsSet.value) { - model.value.open = value - } else { - openInternal.value = value - } + model.value = value }, })This approach:
- Uses the standard
v-model:opensyntax- Eliminates the need for
modelOpenIsSethelper- Removes the non-null assertion
- Simplifies the mental model for users
16-29: NodefaultOpenusages found—review state transition logic
Verified that thedefaultOpenprop has been fully removed. Theopengetter still uses a non-null assertion (model.value.open!) and will flip from internal to model-controlled state if anopenproperty is added at runtime, which can be surprising. Consider replacing it withget() { return model.value.open ?? openInternal.value }and documenting this behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/components/src/bubble/renderers/collapsible-text.vue(1 hunks)
🔇 Additional comments (2)
packages/components/src/bubble/renderers/collapsible-text.vue (2)
36-36: LGTM!The template binding correctly uses the
opencomputed property for both the rotation class and click handler.
39-39: LGTM!The
v-showdirective correctly uses theopencomputed property to control content visibility.
Summary by CodeRabbit
Bug Fixes
Refactor