Skip to content

fix(MultiselectInput+SelectInput): handle undefined and null values#396

Merged
mgoetz-lion5 merged 4 commits intomainfrom
feat/sync-select-value-with-model
Apr 10, 2026
Merged

fix(MultiselectInput+SelectInput): handle undefined and null values#396
mgoetz-lion5 merged 4 commits intomainfrom
feat/sync-select-value-with-model

Conversation

@mgoetz-lion5
Copy link
Copy Markdown
Contributor

Handle null and undefined values

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SelectInput and MultiselectInput components to better handle externally-driven null/undefined model values by clearing internal selections and adding unit tests to validate these transitions.

Changes:

  • Clear the currently selected option in SelectInput when modelValue becomes null/undefined.
  • Make MultiselectInput’s model watcher treat non-array / empty values as “no selection”.
  • Add unit tests covering external modelValue changes for both components.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/components/inputs/SelectInput/SelectInput.vue Clears selectedOption when the bound modelValue becomes null/undefined.
packages/core/src/components/inputs/SelectInput/SelectInput.spec.ts Adds a test asserting the selection updates when modelValue changes externally (including null).
packages/core/src/components/inputs/MultiselectInput/MultiselectInput.vue Updates initialization + watcher logic to reset selections when the external value isn’t a non-empty array.
packages/core/src/components/inputs/MultiselectInput/MultiselectInput.spec.ts Adds a test for external modelValue transitions (including empty array and null).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/components/inputs/SelectInput/SelectInput.spec.ts Outdated
@mgoetz-lion5
Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copilot AI and others added 3 commits April 10, 2026 15:38
…defined handling

- Fix SelectInput.spec.ts: use UI-level assertion (has-content class absence) instead of checking internal vue-multiselect modelValue when null is set
- Fix MultiselectInput.vue onMounted: filter out undefined entries after mapping options to avoid runtime crashes
- Widen MultiselectInput defineModel type to include null | undefined to align public typing with runtime behavior

Agent-Logs-Url: https://github.com/lion5/component-library/sessions/5184580c-45c4-44a5-9908-3bb373588687

Co-authored-by: mgoetz-lion5 <262780482+mgoetz-lion5@users.noreply.github.com>
…undefined safety

Agent-Logs-Url: https://github.com/lion5/component-library/sessions/5184580c-45c4-44a5-9908-3bb373588687

Co-authored-by: mgoetz-lion5 <262780482+mgoetz-lion5@users.noreply.github.com>
…aner option resolution

Agent-Logs-Url: https://github.com/lion5/component-library/sessions/5184580c-45c4-44a5-9908-3bb373588687

Co-authored-by: mgoetz-lion5 <262780482+mgoetz-lion5@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

@copilot apply changes based on the comments in this thread

Applied all three review changes in commit 8f59006:

  1. SelectInput.spec.ts – Replaced the internal vue-multiselect modelValue assertion with a UI-level check (absence of has-content class) when modelValue is set to null, since vue-multiselect returns [] internally even for undefined single-select values.

  2. MultiselectInput.vue onMounted – Added .filter(Boolean) (via flatMap) to eliminate undefined entries that can arise when keys in modelValue aren't present in optionsMap. Also switched the condition to Array.isArray(...) for explicit null/undefined safety.

  3. MultiselectInput.vue defineModel – Widened the type to (string | number | boolean | null)[] | null | undefined so the public API typing aligns with the runtime behavior that already handles null/undefined values.

@mgoetz-lion5 mgoetz-lion5 merged commit 1cf8007 into main Apr 10, 2026
11 checks passed
@mgoetz-lion5 mgoetz-lion5 deleted the feat/sync-select-value-with-model branch April 10, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants