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

Introduction to lightning web component
Introduction to lightning web component Introduction to lightning web component
Introduction to lightning web component Sudipta Deb ☁
 
Successfully creating unlocked package
Successfully creating unlocked packageSuccessfully creating unlocked package
Successfully creating unlocked packageMohith Shrivastava
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce orgRoy Gilad
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patternsusolutions
 
Release & Change management in salesforce
Release & Change management in salesforceRelease & Change management in salesforce
Release & Change management in salesforceKalyan Lanka ☁
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables  lwc vs aura vs. visualforceDynamic input tables  lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforceMike Tetlow
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentationNithesh N
 
Real Time Integration with Salesforce Platform Events
Real Time Integration with Salesforce Platform EventsReal Time Integration with Salesforce Platform Events
Real Time Integration with Salesforce Platform EventsSalesforce Developers
 
認定テクニカルアーキテクト取ろうぜ
認定テクニカルアーキテクト取ろうぜ認定テクニカルアーキテクト取ろうぜ
認定テクニカルアーキテクト取ろうぜHiroki Sato
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
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
 
VirtualBox と Rocky Linux 8 で始める Pacemaker ~ VirtualBox でも STONITH 機能が試せる! Vi...
VirtualBox と Rocky Linux 8 で始める Pacemaker  ~ VirtualBox でも STONITH 機能が試せる! Vi...VirtualBox と Rocky Linux 8 で始める Pacemaker  ~ VirtualBox でも STONITH 機能が試せる! Vi...
VirtualBox と Rocky Linux 8 で始める Pacemaker ~ VirtualBox でも STONITH 機能が試せる! Vi...ksk_ha
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkSalesforce Developers
 
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...Sam Garforth
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce IntegrationJoshua Hoskins
 
Cypress report
Cypress reportCypress report
Cypress reportAdarsh
 
OAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedOAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedCalvin Noronha
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component SmritiSharan1
 
Org dependent salesforce packages
Org dependent salesforce packagesOrg dependent salesforce packages
Org dependent salesforce packagesMohith Shrivastava
 

What's hot (20)

Introduction to lightning web component
Introduction to lightning web component Introduction to lightning web component
Introduction to lightning web component
 
Successfully creating unlocked package
Successfully creating unlocked packageSuccessfully creating unlocked package
Successfully creating unlocked package
 
Decluttering your Salesfroce org
Decluttering your Salesfroce orgDecluttering your Salesfroce org
Decluttering your Salesfroce org
 
Salesforce Integration Patterns
Salesforce Integration PatternsSalesforce Integration Patterns
Salesforce Integration Patterns
 
Release & Change management in salesforce
Release & Change management in salesforceRelease & Change management in salesforce
Release & Change management in salesforce
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables  lwc vs aura vs. visualforceDynamic input tables  lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforce
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
 
Real Time Integration with Salesforce Platform Events
Real Time Integration with Salesforce Platform EventsReal Time Integration with Salesforce Platform Events
Real Time Integration with Salesforce Platform Events
 
認定テクニカルアーキテクト取ろうぜ
認定テクニカルアーキテクト取ろうぜ認定テクニカルアーキテクト取ろうぜ
認定テクニカルアーキテクト取ろうぜ
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
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)
 
VirtualBox と Rocky Linux 8 で始める Pacemaker ~ VirtualBox でも STONITH 機能が試せる! Vi...
VirtualBox と Rocky Linux 8 で始める Pacemaker  ~ VirtualBox でも STONITH 機能が試せる! Vi...VirtualBox と Rocky Linux 8 で始める Pacemaker  ~ VirtualBox でも STONITH 機能が試せる! Vi...
VirtualBox と Rocky Linux 8 で始める Pacemaker ~ VirtualBox でも STONITH 機能が試せる! Vi...
 
Manage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance FrameworkManage Development in Your Org with Salesforce Governance Framework
Manage Development in Your Org with Salesforce Governance Framework
 
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
Salesforce Application Lifecycle Management presented to EA Forum by Sam Garf...
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Cypress report
Cypress reportCypress report
Cypress report
 
OAuth with Salesforce - Demystified
OAuth with Salesforce - DemystifiedOAuth with Salesforce - Demystified
OAuth with Salesforce - Demystified
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
 
Commerce Cloud 101
Commerce Cloud 101Commerce Cloud 101
Commerce Cloud 101
 
Org dependent salesforce packages
Org dependent salesforce packagesOrg dependent salesforce packages
Org dependent salesforce packages
 

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
 
Using Styling Hooks to Customize Your LWC
Using Styling Hooks to Customize Your LWCUsing Styling Hooks to Customize Your LWC
Using Styling Hooks to Customize Your LWCSudipta Deb ☁
 
#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
 

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
 
Using Styling Hooks to Customize Your LWC
Using Styling Hooks to Customize Your LWCUsing Styling Hooks to Customize Your LWC
Using Styling Hooks to Customize Your LWC
 
#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
 

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

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

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!