The problem arises when we are going to create a custom radio button as a web component using Shadow Dom.
Normally when we are using radio buttons, we usually give the same name to the grouped radio boxes, like this.
<input type="radio" name="size" id="small" value="small">
<input type="radio" name="size" id="large" value="large">
But if we define some custom element (like let's say cus-radio) -> we would do it in a way to take the name and id as a input (from parent) and place them in the custom element. That would perfectly work on normal context.
But my problem is with the shadow dom! When we are creating elements inside shadow dom, attributes inside of it is accessible or connected with the outer dom (main dom). So how can we develop a custom radio button, if the name and id properties of it is not accessible or common in the parent dom?
Example:-
We will develop our custom element like this (pseudo code like in angular elements)
radio.html:-
<input type="radio" [name]="name" [id]="id" ...>
TS/Logic file:-
...
component cus-radio {
@Input() name: string;
@Input() id: string;
...
Wherever we are using that:-
<cus-radio [id]="'small'" [name]="'size'" value="small">
<cus-radio [id]="'large'" [name]="'size'" value="large">
The expected behavior should be (as happens in a normal dom), these two radio inputs must co-relate and exists with the mutual understanding of two like it one got checked other one must uncheck etc. But in shadow dom it doesn't. Because those name and id are changed in the shadow dom which have no reference to the parent dom (main dom).
How can we actually create radio inputs in the shadow dom?
<radio-group>
component instead. – Darren