question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best way to integrate with Material Design Components?

See original GitHub issue

This is probably less of an issue and more of an ask, but I’m trying to integrate with https://github.com/material-components/material-components-web/tree/master/packages/mdc-tabs and running into a console error. My code is here:

https://codepen.io/dizzle/pen/VyrMVe

And for sanity, here’s another version without Hyperapp: https://codepen.io/dizzle/pen/xpPPKx

The main thing it’s doing is using the element to initialize the Material Design component, as well as using it as a source of local state so that I can reference it later.

element.mdcComponent = new window.mdc.tabs.MDCTabBar(element);

While the codepen works, the console error showing up whenever a tab is clicked is:

Uncaught Error: Invalid tab component given as activeTab: Tab not found within this component's tab list
    at MDCTabBar.setActiveTab_ (VM554 material-components-web.js:2239)
    at HTMLElement.tabSelectedHandler_ (VM554 material-components-web.js:2151)
    at MDCTab.emit (VM554 material-components-web.js:379)
    at Object.notifySelected (VM554 material-components-web.js:2036)
    at HTMLAnchorElement.MDCTabFoundation._this.clickHandler_ (VM554 material-components-web.js:11772)

which makes me think the element for a Tab is changing at some point, although I don’t see how because destroy is never being called.

This is a screenshot of the exception being thrown:

2018-01-06 12_04_09-developer tools - https___codepen io_dizzle_pen_vyrmve

And these are some console commands I ran to try to confirm that the activeTab was not contained in the tabs array (even though the innerText matches)

2018-01-06 12_05_34-developer tools - https___codepen io_dizzle_pen_vyrmve

I realize that the MDC library is not something you may have worked with before, but do you happen to have any ideas what might be going on here?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
developerdizzlecommented, Jan 8, 2018

I may have found my issue. After debugging, I found that MDCTab constructor was being called twice for each tab. It looks like MDCTabBar automatically calls this for its children. Removing that code seems to have fixed my issue.

2reactions
selfupcommented, Jan 8, 2018

Oh glad you have found a useful way to integrate MDC!

🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - Material Design
Step 1: Webpack with Sass · Step 2: Include CSS for a component · Step 3: Webpack with ES2015 · Step 4: Include...
Read more >
Authoring Components - Material Design
Start with a simple component prototype · Identify host environment interactions · Create the adapter interface · Refactor your existing code into a...
Read more >
Components – Material Design 3
Material Design is an adaptable system of guidelines, components, and tools that support the best practices of user interface design. Backed by open-source...
Read more >
Develop - Web - Material Design
Web 112: Integrating Material Components with web frameworks. Learn how to extend pre-built Material Components into components for any web framework.
Read more >
Get started - Material Design
Develop with Material ... Material is an adaptable system of guidelines, components, and tools that support the best practices of user interface design....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found