SlideShare a Scribd company logo
1 of 29
Download to read offline
Shadow DOM, CSS
and styling hooks in
LWC: what you need
to know
Alba Rivas, Lead Developer Advocate, Salesforce
11 February 2021
Alba Rivas
Lead Developer Advocate
arivas@salesforce.com, @AlbaSFDC
Forward-Looking Statement
Salesforce Confidential. Not for external distribution.
Presentation Name | Slide #
Statement under the Private Securities Litigation Reform Act of 1995:
This presentation contains forward-looking statements about the company’s financial and operating results, which may include expected GAAP and non-GAAP financial and other
operating and non-operating results, including revenue, net income, diluted earnings per share, operating cash flow growth, operating margin improvement, expected revenue
growth, expected current remaining performance obligation growth, expected tax rates, the one-time accounting non-cash charge that was incurred in connection with the
Salesforce.org combination; stock-based compensation expenses, amortization of purchased intangibles, shares outstanding, market growth and sustainability goals. The
achievement or success of the matters covered by such forward-looking statements involves risks, uncertainties and assumptions. If any such risks or uncertainties materialize or if any
of the assumptions prove incorrect, the company’s results could differ materially from the results expressed or implied by the forward-looking statements we make.
The risks and uncertainties referred to above include -- but are not limited to -- risks associated with the effect of general economic and market conditions; the impact of geopolitical
events; the impact of foreign currency exchange rate and interest rate fluctuations on our results; our business strategy and our plan to build our business, including our strategy to be
the leading provider of enterprise cloud computing applications and platforms; the pace of change and innovation in enterprise cloud computing services; the seasonal nature of our
sales cycles; the competitive nature of the market in which we participate; our international expansion strategy; the demands on our personnel and infrastructure resulting from
significant growth in our customer base and operations, including as a result of acquisitions; our service performance and security, including the resources and costs required to avoid
unanticipated downtime and prevent, detect and remediate potential security breaches; the expenses associated with new data centers and third-party infrastructure providers;
additional data center capacity; real estate and office facilities space; our operating results and cash flows; new services and product features, including any efforts to expand our
services beyond the CRM market; our strategy of acquiring or making investments in complementary businesses, joint ventures, services, technologies and intellectual property rights;
the performance and fair value of our investments in complementary businesses through our strategic investment portfolio; our ability to realize the benefits from strategic
partnerships, joint ventures and investments; the impact of future gains or losses from our strategic investment portfolio, including gains or losses from overall market conditions that
may affect the publicly traded companies within the company's strategic investment portfolio; our ability to execute our business plans; our ability to successfully integrate acquired
businesses and technologies, including delays related to the integration of Tableau due to regulatory review by the United Kingdom Competition and Markets Authority; our ability to
continue to grow unearned revenue and remaining performance obligation; our ability to protect our intellectual property rights; our ability to develop our brands; our reliance on
third-party hardware, software and platform providers; our dependency on the development and maintenance of the infrastructure of the Internet; the effect of evolving domestic
and foreign government regulations, including those related to the provision of services on the Internet, those related to accessing the Internet, and those addressing data privacy,
cross-border data transfers and import and export controls; the valuation of our deferred tax assets and the release of related valuation allowances; the potential availability of
additional tax assets in the future; the impact of new accounting pronouncements and tax laws; uncertainties affecting our ability to estimate our tax rate; the impact of expensing
stock options and other equity awards; the sufficiency of our capital resources; factors related to our outstanding debt, revolving credit facility, term loan and loan associated with 50
Fremont; compliance with our debt covenants and lease obligations; current and potential litigation involving us; and the impact of climate change.
Further information on these and other factors that could affect the company’s financial results is included in the reports on Forms 10-K, 10-Q and 8-K and in other filings it makes
with the Securities and Exchange Commission from time to time. These documents are available on the SEC Filings section of the Investor Information section of the company’s
website at www.salesforce.com/investor.
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements, except as required by law.
Agenda
● Shadow DOM
● LWC Shadow DOM implementations
● CSS & LWC
● CSS Custom Properties
● Styling Hooks
● Ways to import and share CSS
● SLDS Validator
Lightning Web Components
Native Shadow DOM
Shadow DOM
#shadow-root
|_h1
|_span
html
|_head
|_title
|_style
|_body
|_h1
|_div
|_span
|_p
|_a
html
|_head
|_title
|_style
|_body
|_h1
|_div →
|_span
|_p
|_a
shadow
boundary
shadow
host
const el = document.querySelector('div');
const shadowRoot = el.attachShadow({mode: 'open'});
shadowRoot.innerHTML = "<h1>I belong to <span>Shadow DOM</span></h1>";
html
|_head
|_title
|_style
|_body
|_h1
|_div
|_h1
|_span
|_span
|_p
|_a
Flattened DOM
Light DOM
Shadow DOM
Native Shadow DOM
Shadow DOM
Encapsulates:
● Markup: shadow DOM elements are queried differently,
and only possible if the shadow tree is ‘open’
● Behaviour: events need to be configured as composed
and bubbles to escape the shadow boundary
○ All UA-dispatched UI events are composed
(click/touch/mouseover/copy/paste, etc.).
● CSS: CSS cascading doesn’t affect inner shadow DOM
elements - inherited CSS properties do. More later!
el.shadowRoot.querySelector('h1')
const selectEvent = new
CustomEvent('contactselect', {
bubbles: true,
composed: true
});
Not available if closed mode
Shadow DOM in Vanilla Web
Components
class cascadingAndInheritance extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
connectedCallback() {
console.log(this.shadowRoot.querySelector('h1'))
}
}
Elements of vanilla Web Components are enclosed in a native Shadow DOM Tree
Native Shadow DOM (Vanilla Web Components)
Shadow DOM in LWC
Elements of LWCs are enclosed in a Native or Synthetic Shadow DOM Tree
class MyLightningWebComponent extends LightningElement {
connectedCallback() {
console.log(this.template.querySelector('h1'))
}
}
LWC OSS (Synthetic)
Shadow DOM in LWC
LWC on platform (Synthetic) - backwards compatibility
LWC OSS (Native) - default
Cascading vs Inheritance
CSS
Cascading → combining CSS rules in different stylesheets that are applied to an
element
Inheritance → some CSS property values set on parent elements are inherited by their
child elements, if no cascaded value found - only some (color, font-...)
Property value =
Property initial value
Cascaded
value?
Inherited
property?
Property value =
Property value on
parent element
Property value =
Cascaded value
YES
NO
YES
NO
Cascading vs Inheritance
CSS
h1 {
color: red;
}
h1 {
color: blue;
}
div {
color: green;
}
span {
color: orange;
}
<h1>Salesforce Mascots Stories</h1>
<div>
<p>Astro and Codey are <span>good friends!</span></p>
</div>
Cascaded value
Inherited value Cascaded Value
Prevent inheritance from affecting your styles
Either explicitly set the color, or revert them to their original state
CSS & LWC OSS - Native
<template>
<h1>I belong to parent component Shadow DOM</h1>
<div><my-cascading-and-inheritance></my-cascading-and-inheritance></div>
</template>
h1 {
color: red;
}
h1 {
color: blue;
}
div {
color: green;
}
span {
color: orange;
}
<template>
<h1>I belong to child component Shadow DOM</h1>
<p>Astro and Codey are <span>good friends!</span></p>
</template>
cascadingAndInheritance.html
cascadingAndInheritanceContainer.html
cascadingAndInheritanceContainer.css
shadow boundary
CSS & LWC / LWC OSS - Synthetic
<template>
<h1>I belong to parent component Shadow DOM</h1>
<div><c-cascading-and-inheritance></c-cascading-and-inheritance></div>
</template>
h1 {
color: red;
}
h1 {
color: blue;
}
div {
color: green;
}
span {
color: orange;
}
<template>
<h1>I belong to child component Shadow DOM</h1>
<p>Astro and Codey are <span>good friends!</span></p>
</template>
cascadingAndInheritance.html
cascadingAndInheritanceContainer.html cascadingAndInheritanceContainer.css
SLDS Styles or
styles loaded
via loadStyle
not scoped!!
CSS Custom Properties
(CSS Variables)
Entities to allow reusing CSS property values
● Defined on a scope, and accessed with var
● Case sensitive
● Can penetrate Shadow DOM
Used in LWC for
● Styling Hooks
● Aura Design Tokens
● SLDS Design Tokens
Need to be allowed explicitly in LWC OSS
Set a Custom Property
Get a Custom Property
Setting CSS Custom Properties from JS
Styling Hooks (beta)
CSS Custom Properties defined in base components and SLDS blueprints to allow
customization
Looking for feedback → sfdc.co/stylinghooks
Global Styling Hooks coming soon!
Styling Hooks (beta)
Best practice: Don’t override standard styles. Use Styling hooks.
Aura Design Tokens
Use CSS Variables to access Aura design tokens both in Aura and LWC
Reuse CSS across Aura and LWC!
.THIS h1 {
color : token(myTitleColor);
}
h1 {
color: var(--c-myTitleColor);
}
<aura:tokens>
<aura:token name="myTitleColor" value="blue"/>
</aura:tokens>
Aura LWC
SLDS Design Tokens
lightningdesignsystem.com/design-tokens
Importing CSS
Single File Multiple Files
Static Resource
Styles scoped globally (same as SLDS) - when using synthetic shadow
Importing CSS
Create a LWC with just the CSS file
Import using the syntax @import <namespace>/<componentname>
Styles scoped to the component
Best practice: create a shared CSS Module with all your CSS Custom Properties
CSS modules
importCSSsharedModule.css
Cascading Order
If different rules for the same selector, the following will have preference, in order:
● Inline styles
● CSS defined in component CSS file (scoped)
● CSS imported using @import (scoped)
● CSS imported with loadStyle (global) - only apply if synthetic
Sharing Tokens and Properties
Create Aura Design Tokens to reuse config across Aura and LWC
Create a Shared CSS Module with all CSS Custom Properties
Global Styling Hooks coming soon!
SLDS Validator
VSCode plugin
Part of Salesforce Extension pack
Smart Suggestions
Recommended tokens and utility
classes, in CSS and HTML
Save Time
Syntax highlighting and code
completion
Summary
● Understand Shadow DOM and the different implementations in LWC
● Master CSS: cascading, inherited and custom properties
● Styling hooks, Aura design tokens and SLDS design token
● Know and choose the best ways to import and share your CSS
● SLDS Validator is your friend!
github.com/albarivas/shadow-dom
github.com/albarivas/shadow-dom-oss
Thank You!

More Related Content

What's hot

Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patternsusolutions
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentationNithesh N
 
Manage Salesforce Like a Pro with Governance
Manage Salesforce Like a Pro with GovernanceManage Salesforce Like a Pro with Governance
Manage Salesforce Like a Pro with GovernanceSalesforce Admins
 
Introduction to lightning web component
Introduction to lightning web component Introduction to lightning web component
Introduction to lightning web component Sudipta Deb ☁
 
Introduction to lightning components
Introduction to lightning componentsIntroduction to lightning components
Introduction to lightning componentsMohith Shrivastava
 
認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinar認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinarSalesforce Developers Japan
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewDhanik Sahni
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelSalesforce Developers
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceJitendra Zaa
 
Lightning Components Introduction
Lightning Components IntroductionLightning Components Introduction
Lightning Components IntroductionDurgesh Dhoot
 
Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)Roy Gilad
 
B2B eCommerce on Salesforce: The Facts
B2B eCommerce on Salesforce: The FactsB2B eCommerce on Salesforce: The Facts
B2B eCommerce on Salesforce: The FactsCloudCraze
 
Single Sign-On and User Management With Salesforce Identity
Single Sign-On and User Management With Salesforce IdentitySingle Sign-On and User Management With Salesforce Identity
Single Sign-On and User Management With Salesforce IdentitySalesforce Developers
 
Salesforce developer training presentation slides
Salesforce developer training presentation slidesSalesforce developer training presentation slides
Salesforce developer training presentation slidesSalesforce Associates
 

What's hot (20)

Lightning web components
Lightning web components Lightning web components
Lightning web components
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patterns
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
 
Manage Salesforce Like a Pro with Governance
Manage Salesforce Like a Pro with GovernanceManage Salesforce Like a Pro with Governance
Manage Salesforce Like a Pro with Governance
 
Introduction to lightning web component
Introduction to lightning web component Introduction to lightning web component
Introduction to lightning web component
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
Introduction to lightning components
Introduction to lightning componentsIntroduction to lightning components
Introduction to lightning components
 
認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinar認証プロバイダによるソーシャルサインオンWebinar
認証プロバイダによるソーシャルサインオンWebinar
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern Overview
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
 
Governor limits
Governor limitsGovernor limits
Governor limits
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Lightning Components Introduction
Lightning Components IntroductionLightning Components Introduction
Lightning Components Introduction
 
Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)Intro to Salesforce Lightning Web Components (LWC)
Intro to Salesforce Lightning Web Components (LWC)
 
B2B eCommerce on Salesforce: The Facts
B2B eCommerce on Salesforce: The FactsB2B eCommerce on Salesforce: The Facts
B2B eCommerce on Salesforce: The Facts
 
Single Sign-On and User Management With Salesforce Identity
Single Sign-On and User Management With Salesforce IdentitySingle Sign-On and User Management With Salesforce Identity
Single Sign-On and User Management With Salesforce Identity
 
Architect day 20181128 - Afternoon Session
Architect day 20181128 - Afternoon SessionArchitect day 20181128 - Afternoon Session
Architect day 20181128 - Afternoon Session
 
Salesforce developer training presentation slides
Salesforce developer training presentation slidesSalesforce developer training presentation slides
Salesforce developer training presentation slides
 

Similar to Shadow DOM, CSS and Styling Hooks in LWC what you need to know

CLE TrailheaDX 2020 Global Gathering
CLE TrailheaDX 2020 Global GatheringCLE TrailheaDX 2020 Global Gathering
CLE TrailheaDX 2020 Global GatheringLynda Kane
 
Lightning Components 101: An Apex Developer's Guide
Lightning Components 101: An Apex Developer's GuideLightning Components 101: An Apex Developer's Guide
Lightning Components 101: An Apex Developer's GuideAdam Olshansky
 
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program Architect
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program ArchitectSalesforce Backup, Restore & Archiving- Adam Best, Senior Program Architect
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program Architectgemziebeth
 
Experience cloud for salesforce user group wellington may 2021
Experience cloud for salesforce user group wellington may 2021Experience cloud for salesforce user group wellington may 2021
Experience cloud for salesforce user group wellington may 2021Anna Loughnan Colquhoun
 
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeave
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeaveDreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeave
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeaveDanielBallinger3
 
Salesforce Learning Journey - Partner Guide to Credentials.pdf
Salesforce Learning Journey - Partner Guide to Credentials.pdfSalesforce Learning Journey - Partner Guide to Credentials.pdf
Salesforce Learning Journey - Partner Guide to Credentials.pdfssuser72de80
 
Summer 23 LWC Updates + Slack Apps.pptx
Summer 23 LWC Updates + Slack Apps.pptxSummer 23 LWC Updates + Slack Apps.pptx
Summer 23 LWC Updates + Slack Apps.pptxKishore B T
 
Austin Developers - New Lighting Web Component Features & #TDX22 Updates
Austin Developers - New Lighting Web Component Features & #TDX22 UpdatesAustin Developers - New Lighting Web Component Features & #TDX22 Updates
Austin Developers - New Lighting Web Component Features & #TDX22 UpdatesNadinaLisbon1
 
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...New Delhi Salesforce Developer Group
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
Kitchener Developer Group's session on "All about events"
Kitchener Developer Group's session on "All about events"Kitchener Developer Group's session on "All about events"
Kitchener Developer Group's session on "All about events"Sudipta Deb ☁
 
Alba Rivas - Building Slack Applications with Bolt.js.pdf
Alba Rivas - Building Slack Applications with Bolt.js.pdfAlba Rivas - Building Slack Applications with Bolt.js.pdf
Alba Rivas - Building Slack Applications with Bolt.js.pdfMarkPawlikowski2
 
Successfully retrieving metadata from salesforce org using packages
Successfully retrieving metadata from salesforce org using packagesSuccessfully retrieving metadata from salesforce org using packages
Successfully retrieving metadata from salesforce org using packagesMohith Shrivastava
 
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2Bangkok Admin Group TrailheaDX 2020 Global Gathering v2
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2Jihun Jung
 
TrailheadX Presentation - 2020 Cluj
TrailheadX Presentation -  2020 ClujTrailheadX Presentation -  2020 Cluj
TrailheadX Presentation - 2020 ClujArpad Komaromi
 
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
#DF19 - Panel: Design Justification & Objection Handling for Architects
#DF19 - Panel: Design Justification & Objection Handling for Architects#DF19 - Panel: Design Justification & Objection Handling for Architects
#DF19 - Panel: Design Justification & Objection Handling for ArchitectsKerry Townsend
 

Similar to Shadow DOM, CSS and Styling Hooks in LWC what you need to know (20)

CLE TrailheaDX 2020 Global Gathering
CLE TrailheaDX 2020 Global GatheringCLE TrailheaDX 2020 Global Gathering
CLE TrailheaDX 2020 Global Gathering
 
Winter '22 highlights
Winter '22 highlightsWinter '22 highlights
Winter '22 highlights
 
Lightning Components 101: An Apex Developer's Guide
Lightning Components 101: An Apex Developer's GuideLightning Components 101: An Apex Developer's Guide
Lightning Components 101: An Apex Developer's Guide
 
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program Architect
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program ArchitectSalesforce Backup, Restore & Archiving- Adam Best, Senior Program Architect
Salesforce Backup, Restore & Archiving- Adam Best, Senior Program Architect
 
Experience cloud for salesforce user group wellington may 2021
Experience cloud for salesforce user group wellington may 2021Experience cloud for salesforce user group wellington may 2021
Experience cloud for salesforce user group wellington may 2021
 
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeave
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeaveDreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeave
Dreamforce 22 Unleash Powerful Data Transforms in Apex with DataWeave
 
Salesforce Learning Journey - Partner Guide to Credentials.pdf
Salesforce Learning Journey - Partner Guide to Credentials.pdfSalesforce Learning Journey - Partner Guide to Credentials.pdf
Salesforce Learning Journey - Partner Guide to Credentials.pdf
 
Summer 23 LWC Updates + Slack Apps.pptx
Summer 23 LWC Updates + Slack Apps.pptxSummer 23 LWC Updates + Slack Apps.pptx
Summer 23 LWC Updates + Slack Apps.pptx
 
Austin Developers - New Lighting Web Component Features & #TDX22 Updates
Austin Developers - New Lighting Web Component Features & #TDX22 UpdatesAustin Developers - New Lighting Web Component Features & #TDX22 Updates
Austin Developers - New Lighting Web Component Features & #TDX22 Updates
 
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...
#ImpactSalesforceSaturday: Prepare for Salesforce Certified Heroku Architectu...
 
TDX Global Gathering - Wellington UG
TDX Global Gathering - Wellington UGTDX Global Gathering - Wellington UG
TDX Global Gathering - Wellington UG
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
Kitchener Developer Group's session on "All about events"
Kitchener Developer Group's session on "All about events"Kitchener Developer Group's session on "All about events"
Kitchener Developer Group's session on "All about events"
 
Alba Rivas - Building Slack Applications with Bolt.js.pdf
Alba Rivas - Building Slack Applications with Bolt.js.pdfAlba Rivas - Building Slack Applications with Bolt.js.pdf
Alba Rivas - Building Slack Applications with Bolt.js.pdf
 
Successfully retrieving metadata from salesforce org using packages
Successfully retrieving metadata from salesforce org using packagesSuccessfully retrieving metadata from salesforce org using packages
Successfully retrieving metadata from salesforce org using packages
 
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2Bangkok Admin Group TrailheaDX 2020 Global Gathering v2
Bangkok Admin Group TrailheaDX 2020 Global Gathering v2
 
TrailheadX Presentation - 2020 Cluj
TrailheadX Presentation -  2020 ClujTrailheadX Presentation -  2020 Cluj
TrailheadX Presentation - 2020 Cluj
 
Intro to Tableau - SL Dev Group.pdf
Intro to Tableau - SL Dev Group.pdfIntro to Tableau - SL Dev Group.pdf
Intro to Tableau - SL Dev Group.pdf
 
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
#DF19 - Panel: Design Justification & Objection Handling for Architects
#DF19 - Panel: Design Justification & Objection Handling for Architects#DF19 - Panel: Design Justification & Objection Handling for Architects
#DF19 - Panel: Design Justification & Objection Handling for Architects
 

More from Sudipta Deb ☁

Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...
Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...
Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...Sudipta Deb ☁
 
Learn how Source Tracking can keep metadata changes in sync between your loca...
Learn how Source Tracking can keep metadata changes in sync between your loca...Learn how Source Tracking can keep metadata changes in sync between your loca...
Learn how Source Tracking can keep metadata changes in sync between your loca...Sudipta Deb ☁
 
Orchestrate all of your salesforce automation with the trigger actions framework
Orchestrate all of your salesforce automation with the trigger actions frameworkOrchestrate all of your salesforce automation with the trigger actions framework
Orchestrate all of your salesforce automation with the trigger actions frameworkSudipta Deb ☁
 
Let's Learn About Heroku and How to Integrate with Salesforce
Let's Learn About Heroku and How to Integrate with SalesforceLet's Learn About Heroku and How to Integrate with Salesforce
Let's Learn About Heroku and How to Integrate with SalesforceSudipta Deb ☁
 
Algorithms design and analysis, part 1
Algorithms  design and analysis, part 1Algorithms  design and analysis, part 1
Algorithms design and analysis, part 1Sudipta Deb ☁
 
Functional programming principles in scala
Functional programming principles in scalaFunctional programming principles in scala
Functional programming principles in scalaSudipta Deb ☁
 
Principles of reactive programming
Principles of reactive programmingPrinciples of reactive programming
Principles of reactive programmingSudipta Deb ☁
 
Automate the development lifecycle with cumulus ci on april 9th, 2020
Automate the development lifecycle with cumulus ci on april 9th, 2020Automate the development lifecycle with cumulus ci on april 9th, 2020
Automate the development lifecycle with cumulus ci on april 9th, 2020Sudipta Deb ☁
 
Dreamforce Global Gathering
Dreamforce Global GatheringDreamforce Global Gathering
Dreamforce Global GatheringSudipta Deb ☁
 
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...Sudipta Deb ☁
 
Kitchener CA Developer Group Presents Everything you need to know about Einst...
Kitchener CA Developer Group Presents Everything you need to know about Einst...Kitchener CA Developer Group Presents Everything you need to know about Einst...
Kitchener CA Developer Group Presents Everything you need to know about Einst...Sudipta Deb ☁
 
Building lightning apps by Daniel Peter
Building lightning apps by Daniel PeterBuilding lightning apps by Daniel Peter
Building lightning apps by Daniel PeterSudipta Deb ☁
 

More from Sudipta Deb ☁ (13)

Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...
Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...
Kitchener Canada Developer Group Event: From Admin to Certified Technical Arc...
 
DevOps 101
DevOps 101DevOps 101
DevOps 101
 
Learn how Source Tracking can keep metadata changes in sync between your loca...
Learn how Source Tracking can keep metadata changes in sync between your loca...Learn how Source Tracking can keep metadata changes in sync between your loca...
Learn how Source Tracking can keep metadata changes in sync between your loca...
 
Orchestrate all of your salesforce automation with the trigger actions framework
Orchestrate all of your salesforce automation with the trigger actions frameworkOrchestrate all of your salesforce automation with the trigger actions framework
Orchestrate all of your salesforce automation with the trigger actions framework
 
Let's Learn About Heroku and How to Integrate with Salesforce
Let's Learn About Heroku and How to Integrate with SalesforceLet's Learn About Heroku and How to Integrate with Salesforce
Let's Learn About Heroku and How to Integrate with Salesforce
 
Algorithms design and analysis, part 1
Algorithms  design and analysis, part 1Algorithms  design and analysis, part 1
Algorithms design and analysis, part 1
 
Functional programming principles in scala
Functional programming principles in scalaFunctional programming principles in scala
Functional programming principles in scala
 
Principles of reactive programming
Principles of reactive programmingPrinciples of reactive programming
Principles of reactive programming
 
Automate the development lifecycle with cumulus ci on april 9th, 2020
Automate the development lifecycle with cumulus ci on april 9th, 2020Automate the development lifecycle with cumulus ci on april 9th, 2020
Automate the development lifecycle with cumulus ci on april 9th, 2020
 
Dreamforce Global Gathering
Dreamforce Global GatheringDreamforce Global Gathering
Dreamforce Global Gathering
 
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...
Kitchener Salesforce Developer Group Event - Introduction to dev ops with Sal...
 
Kitchener CA Developer Group Presents Everything you need to know about Einst...
Kitchener CA Developer Group Presents Everything you need to know about Einst...Kitchener CA Developer Group Presents Everything you need to know about Einst...
Kitchener CA Developer Group Presents Everything you need to know about Einst...
 
Building lightning apps by Daniel Peter
Building lightning apps by Daniel PeterBuilding lightning apps by Daniel Peter
Building lightning apps by Daniel Peter
 

Recently uploaded

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Shadow DOM, CSS and Styling Hooks in LWC what you need to know

  • 1. Shadow DOM, CSS and styling hooks in LWC: what you need to know Alba Rivas, Lead Developer Advocate, Salesforce 11 February 2021
  • 2. Alba Rivas Lead Developer Advocate arivas@salesforce.com, @AlbaSFDC
  • 3. Forward-Looking Statement Salesforce Confidential. Not for external distribution. Presentation Name | Slide # Statement under the Private Securities Litigation Reform Act of 1995: This presentation contains forward-looking statements about the company’s financial and operating results, which may include expected GAAP and non-GAAP financial and other operating and non-operating results, including revenue, net income, diluted earnings per share, operating cash flow growth, operating margin improvement, expected revenue growth, expected current remaining performance obligation growth, expected tax rates, the one-time accounting non-cash charge that was incurred in connection with the Salesforce.org combination; stock-based compensation expenses, amortization of purchased intangibles, shares outstanding, market growth and sustainability goals. The achievement or success of the matters covered by such forward-looking statements involves risks, uncertainties and assumptions. If any such risks or uncertainties materialize or if any of the assumptions prove incorrect, the company’s results could differ materially from the results expressed or implied by the forward-looking statements we make. The risks and uncertainties referred to above include -- but are not limited to -- risks associated with the effect of general economic and market conditions; the impact of geopolitical events; the impact of foreign currency exchange rate and interest rate fluctuations on our results; our business strategy and our plan to build our business, including our strategy to be the leading provider of enterprise cloud computing applications and platforms; the pace of change and innovation in enterprise cloud computing services; the seasonal nature of our sales cycles; the competitive nature of the market in which we participate; our international expansion strategy; the demands on our personnel and infrastructure resulting from significant growth in our customer base and operations, including as a result of acquisitions; our service performance and security, including the resources and costs required to avoid unanticipated downtime and prevent, detect and remediate potential security breaches; the expenses associated with new data centers and third-party infrastructure providers; additional data center capacity; real estate and office facilities space; our operating results and cash flows; new services and product features, including any efforts to expand our services beyond the CRM market; our strategy of acquiring or making investments in complementary businesses, joint ventures, services, technologies and intellectual property rights; the performance and fair value of our investments in complementary businesses through our strategic investment portfolio; our ability to realize the benefits from strategic partnerships, joint ventures and investments; the impact of future gains or losses from our strategic investment portfolio, including gains or losses from overall market conditions that may affect the publicly traded companies within the company's strategic investment portfolio; our ability to execute our business plans; our ability to successfully integrate acquired businesses and technologies, including delays related to the integration of Tableau due to regulatory review by the United Kingdom Competition and Markets Authority; our ability to continue to grow unearned revenue and remaining performance obligation; our ability to protect our intellectual property rights; our ability to develop our brands; our reliance on third-party hardware, software and platform providers; our dependency on the development and maintenance of the infrastructure of the Internet; the effect of evolving domestic and foreign government regulations, including those related to the provision of services on the Internet, those related to accessing the Internet, and those addressing data privacy, cross-border data transfers and import and export controls; the valuation of our deferred tax assets and the release of related valuation allowances; the potential availability of additional tax assets in the future; the impact of new accounting pronouncements and tax laws; uncertainties affecting our ability to estimate our tax rate; the impact of expensing stock options and other equity awards; the sufficiency of our capital resources; factors related to our outstanding debt, revolving credit facility, term loan and loan associated with 50 Fremont; compliance with our debt covenants and lease obligations; current and potential litigation involving us; and the impact of climate change. Further information on these and other factors that could affect the company’s financial results is included in the reports on Forms 10-K, 10-Q and 8-K and in other filings it makes with the Securities and Exchange Commission from time to time. These documents are available on the SEC Filings section of the Investor Information section of the company’s website at www.salesforce.com/investor. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements, except as required by law.
  • 4. Agenda ● Shadow DOM ● LWC Shadow DOM implementations ● CSS & LWC ● CSS Custom Properties ● Styling Hooks ● Ways to import and share CSS ● SLDS Validator
  • 6. Native Shadow DOM Shadow DOM #shadow-root |_h1 |_span html |_head |_title |_style |_body |_h1 |_div |_span |_p |_a html |_head |_title |_style |_body |_h1 |_div → |_span |_p |_a shadow boundary shadow host const el = document.querySelector('div'); const shadowRoot = el.attachShadow({mode: 'open'}); shadowRoot.innerHTML = "<h1>I belong to <span>Shadow DOM</span></h1>"; html |_head |_title |_style |_body |_h1 |_div |_h1 |_span |_span |_p |_a Flattened DOM Light DOM Shadow DOM
  • 7. Native Shadow DOM Shadow DOM Encapsulates: ● Markup: shadow DOM elements are queried differently, and only possible if the shadow tree is ‘open’ ● Behaviour: events need to be configured as composed and bubbles to escape the shadow boundary ○ All UA-dispatched UI events are composed (click/touch/mouseover/copy/paste, etc.). ● CSS: CSS cascading doesn’t affect inner shadow DOM elements - inherited CSS properties do. More later! el.shadowRoot.querySelector('h1') const selectEvent = new CustomEvent('contactselect', { bubbles: true, composed: true }); Not available if closed mode
  • 8. Shadow DOM in Vanilla Web Components class cascadingAndInheritance extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); } connectedCallback() { console.log(this.shadowRoot.querySelector('h1')) } } Elements of vanilla Web Components are enclosed in a native Shadow DOM Tree Native Shadow DOM (Vanilla Web Components)
  • 9. Shadow DOM in LWC Elements of LWCs are enclosed in a Native or Synthetic Shadow DOM Tree class MyLightningWebComponent extends LightningElement { connectedCallback() { console.log(this.template.querySelector('h1')) } }
  • 10. LWC OSS (Synthetic) Shadow DOM in LWC LWC on platform (Synthetic) - backwards compatibility LWC OSS (Native) - default
  • 11. Cascading vs Inheritance CSS Cascading → combining CSS rules in different stylesheets that are applied to an element Inheritance → some CSS property values set on parent elements are inherited by their child elements, if no cascaded value found - only some (color, font-...) Property value = Property initial value Cascaded value? Inherited property? Property value = Property value on parent element Property value = Cascaded value YES NO YES NO
  • 12. Cascading vs Inheritance CSS h1 { color: red; } h1 { color: blue; } div { color: green; } span { color: orange; } <h1>Salesforce Mascots Stories</h1> <div> <p>Astro and Codey are <span>good friends!</span></p> </div> Cascaded value Inherited value Cascaded Value
  • 13. Prevent inheritance from affecting your styles Either explicitly set the color, or revert them to their original state
  • 14. CSS & LWC OSS - Native <template> <h1>I belong to parent component Shadow DOM</h1> <div><my-cascading-and-inheritance></my-cascading-and-inheritance></div> </template> h1 { color: red; } h1 { color: blue; } div { color: green; } span { color: orange; } <template> <h1>I belong to child component Shadow DOM</h1> <p>Astro and Codey are <span>good friends!</span></p> </template> cascadingAndInheritance.html cascadingAndInheritanceContainer.html cascadingAndInheritanceContainer.css shadow boundary
  • 15. CSS & LWC / LWC OSS - Synthetic <template> <h1>I belong to parent component Shadow DOM</h1> <div><c-cascading-and-inheritance></c-cascading-and-inheritance></div> </template> h1 { color: red; } h1 { color: blue; } div { color: green; } span { color: orange; } <template> <h1>I belong to child component Shadow DOM</h1> <p>Astro and Codey are <span>good friends!</span></p> </template> cascadingAndInheritance.html cascadingAndInheritanceContainer.html cascadingAndInheritanceContainer.css SLDS Styles or styles loaded via loadStyle not scoped!!
  • 16. CSS Custom Properties (CSS Variables) Entities to allow reusing CSS property values ● Defined on a scope, and accessed with var ● Case sensitive ● Can penetrate Shadow DOM Used in LWC for ● Styling Hooks ● Aura Design Tokens ● SLDS Design Tokens Need to be allowed explicitly in LWC OSS Set a Custom Property Get a Custom Property
  • 17. Setting CSS Custom Properties from JS
  • 18. Styling Hooks (beta) CSS Custom Properties defined in base components and SLDS blueprints to allow customization Looking for feedback → sfdc.co/stylinghooks Global Styling Hooks coming soon!
  • 19. Styling Hooks (beta) Best practice: Don’t override standard styles. Use Styling hooks.
  • 20. Aura Design Tokens Use CSS Variables to access Aura design tokens both in Aura and LWC Reuse CSS across Aura and LWC! .THIS h1 { color : token(myTitleColor); } h1 { color: var(--c-myTitleColor); } <aura:tokens> <aura:token name="myTitleColor" value="blue"/> </aura:tokens> Aura LWC
  • 22. Importing CSS Single File Multiple Files Static Resource Styles scoped globally (same as SLDS) - when using synthetic shadow
  • 23. Importing CSS Create a LWC with just the CSS file Import using the syntax @import <namespace>/<componentname> Styles scoped to the component Best practice: create a shared CSS Module with all your CSS Custom Properties CSS modules importCSSsharedModule.css
  • 24. Cascading Order If different rules for the same selector, the following will have preference, in order: ● Inline styles ● CSS defined in component CSS file (scoped) ● CSS imported using @import (scoped) ● CSS imported with loadStyle (global) - only apply if synthetic
  • 25. Sharing Tokens and Properties Create Aura Design Tokens to reuse config across Aura and LWC Create a Shared CSS Module with all CSS Custom Properties Global Styling Hooks coming soon!
  • 26. SLDS Validator VSCode plugin Part of Salesforce Extension pack Smart Suggestions Recommended tokens and utility classes, in CSS and HTML Save Time Syntax highlighting and code completion
  • 27. Summary ● Understand Shadow DOM and the different implementations in LWC ● Master CSS: cascading, inherited and custom properties ● Styling hooks, Aura design tokens and SLDS design token ● Know and choose the best ways to import and share your CSS ● SLDS Validator is your friend!