Skip to content

[select] <selectedcontent> does not work with dynamic dom #1182

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

Closed
kbrilla opened this issue Apr 2, 2025 · 4 comments
Closed

[select] <selectedcontent> does not work with dynamic dom #1182

kbrilla opened this issue Apr 2, 2025 · 4 comments
Labels
select These are issues that relate to the select component

Comments

@kbrilla
Copy link

kbrilla commented Apr 2, 2025

When trying to use <selectedoption> with Angular there is a problem. Because of dynamic nature of dom creation in Angular <selectedoption> and <option>s are created dynamicly which can lead to situations that <selectedoption> is created before option and currently <selectedoption> won't clone <option>. This is also problem when <option>s are dynamic.

Original thread in Angular repo: angular/angular#60636
StackBlitz showing the issue: https://stackblitz.com/edit/angular-19-starter-bszk44yd?file=src%2Fmain.ts

@kbrilla kbrilla changed the title [select] order of dom nodes creation [select] <selectedoption> does not work with dynamic dom Apr 2, 2025
@lukewarlow
Copy link
Collaborator

lukewarlow commented Apr 2, 2025

Angular/the web author will probably have to manually clone the option into selectedcontent in first render in that case.

Though there's probably more Angular can do to provide fully dynamic updating behaviour if that's what they want for their users.

@lukewarlow lukewarlow changed the title [select] <selectedoption> does not work with dynamic dom [select] <selectedcontent> does not work with dynamic dom Apr 2, 2025
@lukewarlow lukewarlow added the select These are issues that relate to the select component label Apr 2, 2025
@lukewarlow
Copy link
Collaborator

To provide some context: The current behaviour of the selectedcontent element it went through a bit of iteration. Originally it did clone option contents every time they changed and would have "just worked" for the above case.

However after some extensive discussion it was decided to change this to only set it once the option finishes parsing, when selectedcontent is inserted into the DOM or when the option that's selected is changed.

See https://jakearchibald.com/2024/how-should-selectedoption-work/ for an initial blog that sparked discussion.

A long related discussion in whatwg/html#10520, as well as various issues in the OpenUI repository.

Just providing these as they potentially help clarify the reasoning for the current behaviour. Though there's no objective correct answer here.

@lukewarlow
Copy link
Collaborator

Cc @josepharhar just in case there's anything I'm missing but I think this is as intended and Angular will have to update to handle this due to how their DOM is constructed. There's various mechanisms for triggering the clone but I'm not familiar enough with Angular to know which one is most appropriate.

@josepharhar
Copy link
Collaborator

Thanks Luke, you didn't miss anything. At first I was quite resistant to changing <selectedcontent> from cloning during any mutation to only during changing options, but after I tested it in React and it ended up just working I was OK with it.

It might not be a bad idea for Angular to manually do a clone during its initial render or whenever it modifies the contents of the currently selected <option>.

@lukewarlow lukewarlow closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
select These are issues that relate to the select component
Projects
None yet
Development

No branches or pull requests

3 participants