-
Notifications
You must be signed in to change notification settings - Fork 34
fix(#3248): sync the dropdown values when children are added/removed #3122
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/prs/angular/src/routes/bugs/3248/bug3248.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <div style="width: 1024px; margin: 0 auto; padding: 2rem"> | ||
| <goab-text size="heading-l" mb="xl"> Bug #2333: Dropdown Reset Test </goab-text> | ||
|
|
||
| <goab-text size="body-m" mb="2xl"> | ||
| This test demonstrates the dropdown reset issue. When dropdown items are dynamically removed, | ||
| the dropdown should properly sync its internal state to reflect the updated list of options. | ||
| </goab-text> | ||
|
|
||
| <goab-text size="heading-m" mb="l"> Test Scenario </goab-text> | ||
|
|
||
| <goab-text size="body-s" mb="m"> 1. Select a color from the dropdown below </goab-text> | ||
| <goab-text size="body-s" mb="m"> | ||
| 2. Click one of the buttons to reduce the number of available options | ||
| </goab-text> | ||
| <goab-text size="body-s" mb="m"> | ||
| 3. Open the dropdown again - it should only show the remaining options | ||
| </goab-text> | ||
| <goab-text size="body-s" mb="2xl"> | ||
| 4. The bug occurred when the filtered options weren't synced after items were destroyed | ||
| </goab-text> | ||
|
|
||
| <goab-text size="body-m" mb="m"> | ||
| Currently showing {{ colorsCount }} color(s): {{ colorsList }} | ||
| </goab-text> | ||
|
|
||
| <goab-text size="body-m" mb="m"> | ||
| Selected value: {{ selectedColor || "None" }} | ||
| </goab-text> | ||
|
|
||
| <goab-dropdown | ||
| name="favcolor" | ||
| placeholder="Select a color" | ||
| [value]="selectedColor" | ||
| (onChange)="onChange($event)" | ||
| mb="xl" | ||
| > | ||
| @for (color of colors; track color) { | ||
| <goab-dropdown-item [label]="color" [value]="color"></goab-dropdown-item> | ||
| } | ||
| </goab-dropdown> | ||
|
|
||
| <div style="display: flex; gap: 1rem; margin-bottom: 1rem"> | ||
| <goab-button type="secondary" (click)="reduceToOne()"> | ||
| Reduce to 1 item (blue) | ||
| </goab-button> | ||
| <goab-button type="secondary" (click)="reduceToTwo()"> | ||
| Reduce to 2 items (green, yellow) | ||
| </goab-button> | ||
| <goab-button type="primary" (click)="resetToAll()"> Reset to all items </goab-button> | ||
| </div> | ||
|
|
||
| <goab-text size="body-s" mb="m" mt="2xl"> | ||
| <strong>Expected behavior:</strong> After clicking a reduction button, opening the dropdown | ||
| should only display the items that remain in the list. | ||
| </goab-text> | ||
| <goab-text size="body-s"> | ||
| <strong>Bug behavior (before fix):</strong> The dropdown would still show all original items | ||
| even after they were removed, because syncFilteredOptions() wasn't called when child items | ||
| were destroyed. | ||
| </goab-text> | ||
| </div> |
45 changes: 45 additions & 0 deletions
45
apps/prs/angular/src/routes/bugs/3248/bug3248.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Component } from "@angular/core"; | ||
| import { CommonModule } from "@angular/common"; | ||
| import { | ||
| GoabButton, | ||
| GoabDropdown, | ||
| GoabDropdownItem, | ||
| GoabDropdownOnChangeDetail, | ||
| GoabText, | ||
| } from "@abgov/angular-components"; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| selector: "abgov-bug3248", | ||
| templateUrl: "./bug3248.component.html", | ||
| imports: [CommonModule, GoabButton, GoabDropdown, GoabDropdownItem, GoabText], | ||
| }) | ||
| export class Bug3248Component { | ||
| colors = ["red", "blue", "green", "yellow", "purple"]; | ||
| selectedColor = ""; | ||
|
|
||
| reduceToOne(): void { | ||
| this.colors = ["blue"]; | ||
| } | ||
|
|
||
| reduceToTwo(): void { | ||
| this.colors = ["green", "yellow"]; | ||
| } | ||
|
|
||
| resetToAll(): void { | ||
| this.colors = ["red", "blue", "green", "yellow", "purple"]; | ||
| } | ||
|
|
||
| onChange(detail: GoabDropdownOnChangeDetail): void { | ||
| console.log("Dropdown changed:", detail); | ||
| this.selectedColor = Array.isArray(detail.value) ? detail.value[0] : detail.value; | ||
| } | ||
|
|
||
| get colorsList(): string { | ||
| return this.colors.join(", "); | ||
| } | ||
|
|
||
| get colorsCount(): number { | ||
| return this.colors.length; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import React, { useState } from "react"; | ||
| import { | ||
| GoabButton, | ||
| GoabDropdown, | ||
| GoabDropdownItem, | ||
| GoabText, | ||
| } from "@abgov/react-components"; | ||
| import { GoabDropdownOnChangeDetail } from "@abgov/ui-components-common"; | ||
|
|
||
| export function Bug3248Route() { | ||
| const [colors, setColors] = useState<string[]>(["red", "blue", "green", "yellow", "purple"]); | ||
| const [selectedColor, setSelectedColor] = useState<string>(""); | ||
|
|
||
| const reduceToOne = () => { | ||
| setColors(["blue"]); | ||
| }; | ||
|
|
||
| const reduceToTwo = () => { | ||
| setColors(["green", "yellow"]); | ||
| }; | ||
|
|
||
| const resetToAll = () => { | ||
| setColors(["red", "blue", "green", "yellow", "purple"]); | ||
| }; | ||
|
|
||
| const onChange = (detail: GoabDropdownOnChangeDetail) => { | ||
| console.log("Dropdown changed:", detail); | ||
| setSelectedColor(detail.value || ""); | ||
| }; | ||
|
|
||
| return ( | ||
| <div style={{ width: "1024px", margin: "0 auto", padding: "2rem" }}> | ||
| <GoabText size="heading-l" mb="xl"> | ||
| Bug #2333: Dropdown Reset Test | ||
| </GoabText> | ||
|
|
||
| <GoabText size="body-m" mb="2xl"> | ||
| This test demonstrates the dropdown reset issue. When dropdown items are dynamically | ||
| removed, the dropdown should properly sync its internal state to reflect the updated | ||
| list of options. | ||
| </GoabText> | ||
|
|
||
| <GoabText size="heading-m" mb="l"> | ||
| Test Scenario | ||
| </GoabText> | ||
|
|
||
| <GoabText size="body-s" mb="m"> | ||
| 1. Select a color from the dropdown below | ||
| </GoabText> | ||
| <GoabText size="body-s" mb="m"> | ||
| 2. Click one of the buttons to reduce the number of available options | ||
| </GoabText> | ||
| <GoabText size="body-s" mb="m"> | ||
| 3. Open the dropdown again - it should only show the remaining options | ||
| </GoabText> | ||
| <GoabText size="body-s" mb="2xl"> | ||
| 4. The bug occurred when the filtered options weren't synced after items were destroyed | ||
| </GoabText> | ||
|
|
||
| <GoabText size="body-m" mb="m"> | ||
| Currently showing {colors.length} color(s): {colors.join(", ")} | ||
| </GoabText> | ||
|
|
||
| <GoabText size="body-m" mb="m"> | ||
| Selected value: {selectedColor || "None"} | ||
| </GoabText> | ||
|
|
||
| <GoabDropdown | ||
| name="favcolor" | ||
| placeholder="Select a color" | ||
| value={selectedColor} | ||
| onChange={onChange} | ||
| mb="xl" | ||
| > | ||
| {colors.map((color) => ( | ||
| <GoabDropdownItem key={color} label={color} value={color} /> | ||
| ))} | ||
| </GoabDropdown> | ||
|
|
||
| <div style={{ display: "flex", gap: "1rem", marginBottom: "1rem" }}> | ||
| <GoabButton type="secondary" onClick={reduceToOne}> | ||
| Reduce to 1 item (blue) | ||
| </GoabButton> | ||
| <GoabButton type="secondary" onClick={reduceToTwo}> | ||
| Reduce to 2 items (green, yellow) | ||
| </GoabButton> | ||
| <GoabButton type="primary" onClick={resetToAll}> | ||
| Reset to all items | ||
| </GoabButton> | ||
| </div> | ||
|
|
||
| <GoabText size="body-s" mb="m" mt="2xl"> | ||
| <strong>Expected behavior:</strong> After clicking a reduction button, opening the | ||
| dropdown should only display the items that remain in the list. | ||
| </GoabText> | ||
| <GoabText size="body-s"> | ||
| <strong>Bug behavior (before fix):</strong> The dropdown would still show all original | ||
| items even after they were removed, because syncFilteredOptions() wasn't called when | ||
| child items were destroyed. | ||
| </GoabText> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.