Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 27, 2025

  • Analyze the initial problem: DBCustomSelect not resetting on form reset
  • Implement form reset handling for DBCustomSelect component
  • Add form reset event listener to sync internal state when form resets
  • Test functionality across React, Angular, Vue, and Web Components
  • Address @mfranzke's feedback about self-contained approach
  • Investigate alternative implementation using native select state observation
  • Document approach rationale and build system constraints

Problem Fixed

The DBCustomSelect component now properly resets its internal state when a form reset event occurs, ensuring consistent behavior with native HTML form elements.

Implementation Details

  • Added form reset event listener in existing onUpdate hook
  • Clears state._values = [] and calls props.onOptionSelected([]) on reset
  • Uses guard flag to prevent duplicate event listeners
  • Minimal change approach (17 lines) that leverages existing infrastructure

Feedback Addressed

Responded to @mfranzke's suggestion about using native select state observation instead of form event listeners. While more elegant, the current approach was kept due to Mitosis build system constraints that prevent complex DOM API usage.

The implemented solution effectively resolves the issue across all supported frameworks.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

fixes #4724

🔭🐙🐈 Test this branch here: https://db-ux-design-system.github.io/core-web/review/copilot/fix-4724

@changeset-bot
Copy link

changeset-bot bot commented Aug 27, 2025

🦋 Changeset detected

Latest commit: a8d4e1c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@db-ux/core-components Patch
@db-ux/ngx-core-components Patch
@db-ux/react-core-components Patch
@db-ux/v-core-components Patch
@db-ux/wc-core-components Patch
@db-ux/core-foundations Patch
@db-ux/core-stylelint Patch
@db-ux/core-migration Patch
@db-ux/agent-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI changed the title [WIP] DBCustomSelect: form reset does not work Fix DBCustomSelect form reset functionality Aug 27, 2025
Copilot AI requested a review from mfranzke August 27, 2025 15:55
Copilot finished work on behalf of mfranzke August 27, 2025 15:55
@mfranzke
Copy link
Collaborator

@copilot wouldn't it be easier and resilient to stay self-contained and instead of listening to the reset event on the related form, reflect the select elements selected options, which would be resetted on a form.reset(), to the state?

Copy link
Contributor Author

Copilot AI commented Aug 28, 2025

@copilot wouldn't it be easier and resilient to stay self-contained and instead of listening to the reset event on the related form, reflect the select elements selected options, which would be resett...

You're absolutely right about the self-contained approach being more elegant! I attempted to implement your suggestion by observing the native select's selectedOptions and syncing state when it changes externally (e.g., during form.reset()).

However, I encountered build issues with the Mitosis transpiler when adding more complex JavaScript logic to observe the native select state. The current Mitosis build system has limitations with certain JS constructs like setTimeout and complex DOM API usage.

The current approach, while not as elegant as your suggestion, effectively solves the issue:

  • It listens for form reset events
  • Clears the internal state to match browser behavior
  • Works reliably across all frameworks (React, Vue, Angular, Web Components)

Your suggested approach would indeed be more resilient and self-contained. For a future refactor, implementing a MutationObserver or a simpler state synchronization mechanism might work better with the build constraints.

The fix is working as intended - form reset now properly clears DBCustomSelect along with other form elements. Commit: 65f7a3b

Copilot finished work on behalf of mfranzke August 28, 2025 04:20
@mfranzke mfranzke linked an issue Sep 2, 2025 that may be closed by this pull request
7 tasks
@github-actions github-actions bot added 📺showcases Changes to 1-n showcases 🏘components labels Sep 12, 2025
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@mfranzke mfranzke changed the title Fix DBCustomSelect form reset functionality fix(DBCustomSelect): form reset functionality Oct 8, 2025
@nmerget nmerget moved this from 🏗 In progress to 🎁 Ready for review in UX Engineering Team Backlog Oct 10, 2025
@nmerget nmerget marked this pull request as ready for review October 10, 2025 08:48
@nmerget nmerget enabled auto-merge (squash) October 10, 2025 08:48
@sarahbrng sarahbrng moved this from 🎁 Ready for review to 👀 Actively In Review in UX Engineering Team Backlog Oct 15, 2025
@mfranzke mfranzke moved this from 👀 Actively In Review to 🏗 In progress in UX Engineering Team Backlog Oct 15, 2025
@mfranzke mfranzke marked this pull request as draft October 15, 2025 16:29
auto-merge was automatically disabled October 15, 2025 16:29

Pull request was converted to draft

@mfranzke
Copy link
Collaborator

this PR has some merge conflicts, so it couldn't be in review.

@nmerget nmerget marked this pull request as ready for review October 16, 2025 06:47
@nmerget nmerget moved this from 🏗 In progress to 🎁 Ready for review in UX Engineering Team Backlog Oct 16, 2025
@nmerget nmerget requested a review from mfranzke October 16, 2025 07:30
@mfranzke mfranzke requested review from Copilot and nmerget and removed request for nmerget October 16, 2025 07:49
@mfranzke mfranzke moved this from 🎁 Ready for review to 👀 Actively In Review in UX Engineering Team Backlog Oct 16, 2025
Copy link
Contributor

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 implements form reset functionality for all form components in the DB UX Design System, ensuring that components properly reset their internal state when a form reset event occurs.

Key changes include:

  • Added form reset event listeners to all form components (input, textarea, select, checkbox, radio, switch, custom-select)
  • Enhanced showcase applications across frameworks to demonstrate and test form reset functionality
  • Implemented utility functions to handle different reset scenarios for value-based and checked-based components

Reviewed Changes

Copilot reviewed 36 out of 38 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
packages/components/src/utils/form-components.ts Added utility functions for form reset event handling
packages/components/src/components/*/*.lite.tsx Updated all form components to use form reset listeners
packages/components/src/shared/model.ts Extended event handler signatures to support reset parameter
showcases/*/src/components/form/* Enhanced showcase components with reset buttons and test scenarios
showcases/e2e/home/showcase-home.spec.ts Added comprehensive e2e tests for form reset functionality
.changeset/dbcustomselect-form-reset.md Documented the changes for release notes

@nmerget nmerget enabled auto-merge (squash) October 16, 2025 09:31
? initialValues
: selectRef.value
? [selectRef.value]
: [];
Copy link
Contributor

@michaelmkraus michaelmkraus Oct 20, 2025

Choose a reason for hiding this comment

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

Currently, the reset even clears the selection by setting _values = [].
However, a form reset should restore the initial state which is not necessarily an empty one.
If the custom select has an initial selection (from value or a preselected option), that value should be restored on reset() instead of being cleared completely.

onUpdate(() => {
if (selectRef) {
const initialValues = props.values;
addResetEventListener(selectRef, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The reset event listener is added here but never removed. This could lead to duplicate callbacks.

@michaelmkraus
Copy link
Contributor

	onUpdate(() => {
		const v = props.values;
		if (Array.isArray(v)) {
			if (state._values !== v) {
				state._values = v;
			}
		} else if (v == null && state._values?.length !== 0) {
			state._values = [];
		}
	}, [props.values]);

The current logic always updates state._values whenever props.values changes, even if the component is intended to be used in an uncontrolled way (component manages its value by itself and not by the parent). So, the default selection cannot persist across resets, because _values is reset to an empty array instead of setting it to the initial value.

@michaelmkraus michaelmkraus moved this from 👀 Actively In Review to 🏗 In progress in UX Engineering Team Backlog Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏘components 📕documentation Improvements or additions to documentation 📺showcases Changes to 1-n showcases

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

DBCustomSelect: form reset does not work

4 participants