SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Web Components
A sneak peak into Shadow DOM
Kunjan Thakkar
November 2014
 Sr. Developer with Synerzip Softech
 5+ years of development experience
 Mobile Application development in Android, J2ME, Blackberry
 Web development using Javascript, HTML5, AngularJS,
Polymer
Who am I?
 Web Components are a new set of web platform features
that enable developers to build applications in a declarative,
composable way.
What are web components?
What all web components are
available to us?
Custom Elements
The ability to make browser
“learn” new vocabulary. Create
and use new types of DOM
elements.
Shadow DOM
Establish and maintain functional
boundaries resulting into better
encapsulation
Templates
The ability to declare DOM
subtrees and manipulate them to
instantiate document fragments
HTML Imports
Include and reuse HTML
documents in other HTML
documents.
Shadow DOM
Encapsulation at work!!
 Shadow DOM is an emerging web standard that gives
developers access to style and DOM scoping.
 Shadow DOM is a tree of nodes attached to a host.
What is a Shadow DOM?
Ok got it! But why would I need it for
my components?
var shadowRoot = host.createShadowRoot();
shadowRoot.appendChild(shadowChildren);
Creating a shadow root
How does the shadow DOM work?
The two trees
 CSS selectors don't cross the shadow boundary.
 CSS styles defined inside a shadow tree are scoped to the
shadow root.
 Elements added to the Shadow Root won't be queried.
Encapsulation
 The host’s children can then be pulled into the shadow tree.
 <content> tag
Insertion Points
 Allows you to add content selectively
 By giving <content> tag a select attribute with CSS selector as a
value, you can distribute host's content to wherever you want.
 select attribute can only take direct children of the host
element. For example, you can NOT assign descendant
elements to the select attribute:
 <div id="host"> <div class="child"> <h1>This is Shadow DOM</h1>
</div> </div> <content select=".child h1"></content> // Not allowed
The ‘select’ attribute
 From host element
 Deep
 Shadow
 From shadow
 host
 host-context
 Content
Breaking the shadow boundaries
 applyAuthorStyles – let the document css style to style
shadow dom as well
 resetStyleInheritance = apply only direct styles, don’t apply
inherited styles
Breaking boundaries continues..
 The youngest shadow root is finally rendered.
 The older shadows can be brought into the youngest
shadow using <shadow> insertion point.
 Shadow insertion point
 The children of the older shadow roots can be pulled in into the
shadow tree
 If multiple <shadow> insertion points exist in a shadow tree,
only the first is recognized. The rest are ignored.
Working with multiple shadows
 Key to encapsulation.
 Helps us to separate content from presentation
 Enables us to have better composition of the DOM.
 Establish functional boundaries in a document tree.
Benefits of using shadow DOM
 Web Components are a way of standardizing widgets and
plugins.
 Web components help us to :
 Write meaningful and maintainable code
 Create reusable modules.
 Offer encapsulation and modularity.
Wrapping up..
 It first started behind a flag in Chrome 27 and Chrome 31 is
the first to have true support for the updated spec
 Feature detection
function hasSupport() {
return 'registerElement' in document;
}
if (hasSupport()) {
console.log('Custom Elements are supported');
} else {
console.log('Custom Elements not supported');
}
Browser Support
 http://webcomponents.org/
 http://www.html5rocks.com/en/tutorials/webcomponents/c
ustomelements/
 http://css-tricks.com/modular-future-web-components/
 http://www.html5rocks.com/en/tutorials/webcomponents/s
hadowdom/
 http://www.html5rocks.com/en/tutorials/webcomponents/s
hadowdom-201/
 http://www.html5rocks.com/en/tutorials/webcomponents/s
hadowdom-301/
References
Thank you!

Weitere ähnliche Inhalte

Ähnlich wie Web components

Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View EncapsulationJennifer Estrada
 
Web components
Web componentsWeb components
Web componentsMohd Saeed
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the futureDA-14
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web componentImam Raza
 
Web Components
Web ComponentsWeb Components
Web ComponentsFITC
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is HereGil Fink
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsGil Fink
 
Web components
Web componentsWeb components
Web componentsNoam Kfir
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Webcomponents TLV October 2014
Webcomponents TLV October 2014Webcomponents TLV October 2014
Webcomponents TLV October 2014Dmitry Bakaleinik
 
Implementing Vanilla Web Components
Implementing Vanilla Web ComponentsImplementing Vanilla Web Components
Implementing Vanilla Web Componentssonumanoj
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web componentsMike North
 
How else does Adobe help in HTML5 development?
How else does Adobe help in HTML5 development?How else does Adobe help in HTML5 development?
How else does Adobe help in HTML5 development?bhaktipingale
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSSAndrew Rota
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoDamalie Wasukira
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerErik Isaksen
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsclimboid
 

Ähnlich wie Web components (20)

Angular View Encapsulation
Angular View EncapsulationAngular View Encapsulation
Angular View Encapsulation
 
Web components
Web componentsWeb components
Web components
 
Web Components: back to the future
Web Components: back to the futureWeb Components: back to the future
Web Components: back to the future
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Web Components
Web ComponentsWeb Components
Web Components
 
Web Components - The Future is Here
Web Components - The Future is HereWeb Components - The Future is Here
Web Components - The Future is Here
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Web components
Web componentsWeb components
Web components
 
Web components
Web componentsWeb components
Web components
 
Webcomponents TLV October 2014
Webcomponents TLV October 2014Webcomponents TLV October 2014
Webcomponents TLV October 2014
 
Implementing Vanilla Web Components
Implementing Vanilla Web ComponentsImplementing Vanilla Web Components
Implementing Vanilla Web Components
 
Modern Web UI - Web components
Modern Web UI - Web componentsModern Web UI - Web components
Modern Web UI - Web components
 
Webcomponents v2
Webcomponents v2Webcomponents v2
Webcomponents v2
 
How else does Adobe help in HTML5 development?
How else does Adobe help in HTML5 development?How else does Adobe help in HTML5 development?
How else does Adobe help in HTML5 development?
 
Polymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot CampPolymer Web Framework - Swecha Boot Camp
Polymer Web Framework - Swecha Boot Camp
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 
Web 2.0
Web 2.0Web 2.0
Web 2.0
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict Ayiko
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
 

Kürzlich hochgeladen

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 

Kürzlich hochgeladen (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 

Web components

  • 1. Web Components A sneak peak into Shadow DOM Kunjan Thakkar November 2014
  • 2.  Sr. Developer with Synerzip Softech  5+ years of development experience  Mobile Application development in Android, J2ME, Blackberry  Web development using Javascript, HTML5, AngularJS, Polymer Who am I?
  • 3.  Web Components are a new set of web platform features that enable developers to build applications in a declarative, composable way. What are web components?
  • 4. What all web components are available to us? Custom Elements The ability to make browser “learn” new vocabulary. Create and use new types of DOM elements. Shadow DOM Establish and maintain functional boundaries resulting into better encapsulation Templates The ability to declare DOM subtrees and manipulate them to instantiate document fragments HTML Imports Include and reuse HTML documents in other HTML documents.
  • 6.  Shadow DOM is an emerging web standard that gives developers access to style and DOM scoping.  Shadow DOM is a tree of nodes attached to a host. What is a Shadow DOM?
  • 7. Ok got it! But why would I need it for my components?
  • 8. var shadowRoot = host.createShadowRoot(); shadowRoot.appendChild(shadowChildren); Creating a shadow root
  • 9. How does the shadow DOM work?
  • 11.  CSS selectors don't cross the shadow boundary.  CSS styles defined inside a shadow tree are scoped to the shadow root.  Elements added to the Shadow Root won't be queried. Encapsulation
  • 12.  The host’s children can then be pulled into the shadow tree.  <content> tag Insertion Points
  • 13.  Allows you to add content selectively  By giving <content> tag a select attribute with CSS selector as a value, you can distribute host's content to wherever you want.  select attribute can only take direct children of the host element. For example, you can NOT assign descendant elements to the select attribute:  <div id="host"> <div class="child"> <h1>This is Shadow DOM</h1> </div> </div> <content select=".child h1"></content> // Not allowed The ‘select’ attribute
  • 14.  From host element  Deep  Shadow  From shadow  host  host-context  Content Breaking the shadow boundaries
  • 15.  applyAuthorStyles – let the document css style to style shadow dom as well  resetStyleInheritance = apply only direct styles, don’t apply inherited styles Breaking boundaries continues..
  • 16.  The youngest shadow root is finally rendered.  The older shadows can be brought into the youngest shadow using <shadow> insertion point.  Shadow insertion point  The children of the older shadow roots can be pulled in into the shadow tree  If multiple <shadow> insertion points exist in a shadow tree, only the first is recognized. The rest are ignored. Working with multiple shadows
  • 17.  Key to encapsulation.  Helps us to separate content from presentation  Enables us to have better composition of the DOM.  Establish functional boundaries in a document tree. Benefits of using shadow DOM
  • 18.  Web Components are a way of standardizing widgets and plugins.  Web components help us to :  Write meaningful and maintainable code  Create reusable modules.  Offer encapsulation and modularity. Wrapping up..
  • 19.  It first started behind a flag in Chrome 27 and Chrome 31 is the first to have true support for the updated spec  Feature detection function hasSupport() { return 'registerElement' in document; } if (hasSupport()) { console.log('Custom Elements are supported'); } else { console.log('Custom Elements not supported'); } Browser Support
  • 20.  http://webcomponents.org/  http://www.html5rocks.com/en/tutorials/webcomponents/c ustomelements/  http://css-tricks.com/modular-future-web-components/  http://www.html5rocks.com/en/tutorials/webcomponents/s hadowdom/  http://www.html5rocks.com/en/tutorials/webcomponents/s hadowdom-201/  http://www.html5rocks.com/en/tutorials/webcomponents/s hadowdom-301/ References

Hinweis der Redaktion

  1. Web Components are a collection of standards which are working their way through the W3C. They enable truly encapsulated and reusable components for the web.
  2. The shadow tree replaces all of the host’s content. The contents inside the shadow tree are rendered.
  3. Shadow:: -If an element has at least one shadow tree, the ::shadow pseudo-element matches the shadow root itself. It allows you to write selectors that style nodes internal to an element's shadow dom. Style host - The :host selector has low specificity by design, so it’s easier for the document to override it if it needs to. In this case the document style for .widget beats out the shadow style for :host. /*body /deep/ span {*/ /*color: red*/ /*}*/ /*body ::shadow > span {*/ /*color: blue;*/ /*}*/