Skip to content
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

mwc-radio does not properly group when used in lit-element map or repeat. #282

Closed
aarondrabeck opened this issue May 21, 2019 · 3 comments · Fixed by #553
Closed

mwc-radio does not properly group when used in lit-element map or repeat. #282

aarondrabeck opened this issue May 21, 2019 · 3 comments · Fixed by #553
Labels
Type: Bug Something isn't working

Comments

@aarondrabeck
Copy link
Contributor

The root node of a mwc-radio in a lit repeat/map is a document fragment with a text node, mwc-radio and text-node. This means each mwc-radio get its own unique selection controller, preventing the selection controller from working.

https://github.com/material-components/material-components-web-components/blob/8d2ab311e8cd24f2e82e91f89976e61d846098ad/packages/radio/src/selection-controller.ts#L41

A crude work-around is to override the _selectionController for each checkbox manually and call register, overriding the default improper behavior.

firstUpdated()   //true parent of all checkbox's in a group
 if (!window['ShadyDOM'] || !window['ShadyDOM']['inUse']) {
      const _selectionController = SelectionController.getController(this);
      for (const radio of this.radioBoxes) {
        // tslint:disable-next-line: no-any
        (radio as any)._selectionController = _selectionController;

        // Overrides the selection controller for the radio buttons so
        //they properly share a controller.
        _selectionController.register(radio);
      }
    }
@eskan
Copy link
Contributor

eskan commented May 21, 2019

#279

@aomarks aomarks added Type: Bug Something isn't working Component: Radio labels Aug 14, 2019
@lucsoft
Copy link

lucsoft commented Oct 9, 2019

i fixed this issue like so

/**
 * Fixes Radio Buttens (can be removed in later versions)
 */
public updated()
{
    var dialog = this.renderRoot.querySelector("mwc-dialog");
    if (dialog == undefined) return;
    var radios: any = dialog.querySelectorAll('mwc-radio');
    const sControler = SelectionController.getController(<HTMLElement>dialog);
    for (let index = 0; index < radios.length; index++)
    {
        const element = radios[ index ];
        element._selectionController = sControler;
        sControler.register(element);
    }
    console.log(this);
}

aomarks added a commit that referenced this issue Oct 11, 2019
…aneously

Selection groups are keyed by root (document or shadow root). Before, we created our selection group controller at construction. This is fine when creating and connecting at the same time (e.g. in HTML, or in a simple lit template), but fails otherwise, because we get the wrong root. Now we defer creating our controller until connectedCallback, so that we always get the correct root.

Fixes #282

Supersedes #279

PiperOrigin-RevId: 274220064
polymer-github-robot pushed a commit that referenced this issue Oct 11, 2019
…aneously

Selection groups are keyed by root (document or shadow root). Before, we created our selection group controller at construction. This is fine when creating and connecting at the same time (e.g. in HTML, or in a simple lit template), but fails otherwise, because we get the wrong root. Now we defer creating our controller until connectedCallback, so that we always get the correct root.

Fixes #282

Supersedes #279

PiperOrigin-RevId: 274220064
polymer-github-robot pushed a commit that referenced this issue Oct 11, 2019
…aneously

Selection groups are keyed by root (document or shadow root). Before, we created our selection group controller at construction. This is fine when creating and connecting at the same time (e.g. in HTML, or in a simple lit template), but fails otherwise, because we get the wrong root. Now we defer creating our controller until connectedCallback, so that we always get the correct root.

Fixes #282

Supersedes #279

(Also small fix to mwc-textarea.test.ts to avoid use of any)

PiperOrigin-RevId: 274220064
aomarks added a commit that referenced this issue Oct 11, 2019
…aneously

Selection groups are keyed by root (document or shadow root). Before, we created our selection group controller at construction. This is fine when creating and connecting at the same time (e.g. in HTML, or in a simple lit template), but fails otherwise, because we get the wrong root. Now we defer creating our controller until connectedCallback, so that we always get the correct root.

Fixes #282

Supersedes #279

(Also small fix to mwc-textarea.test.ts to avoid use of any)

PiperOrigin-RevId: 274220064
polymer-github-robot pushed a commit that referenced this issue Oct 11, 2019
…aneously

Selection groups are keyed by root (document or shadow root). Before, we created our selection group controller at construction. This is fine when creating and connecting at the same time (e.g. in HTML, or in a simple lit template), but fails otherwise, because we get the wrong root. Now we defer creating our controller until connectedCallback, so that we always get the correct root.

Fixes #282

Supersedes #279

(Also small fix to mwc-textarea.test.ts to avoid use of any)

PiperOrigin-RevId: 274220064
@aomarks
Copy link
Collaborator

aomarks commented Oct 11, 2019

Just published version 0.10.0 that includes this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
4 participants