Miriam Suzanne, an expert in Shadow DOM and 'open styling' problems, joins Brian Kardell and Eric Meyer on Igalia Chats. They discuss the history and development of the Shadow DOM, CSS-based DOM segmentation and selectors, managing styles in custom elements, coordinating layers in component and page authoring, customization and feedback, and the exploration of layer names and intentional crossover.
Custom elements and shadow DOM provide encapsulation and reusability in web development, but finding a balance between their benefits and easy customization is a current challenge.
Open Styleable and Donut Scope are two proposed solutions for styling web components, aiming to provide default styles while allowing page authors to override and customize those styles.
Deep dives
Custom elements and shadow DOM: Exploring the current trends
Custom elements and shadow DOM are currently gaining momentum in web development. While custom elements are often associated with the use of shadow DOM, it is important to note that they can also be used without it. Shadow DOM provides encapsulation and helps in creating reusable components, while custom elements allow developers to define their own HTML elements with custom functionality. However, there has been a debate regarding when and how to use shadow DOM, as it can limit the ability to style and interact with components. Different approaches, such as the concept of named layers, have been proposed to address this issue. Overall, the development community is actively exploring ways to balance the benefits of shadow DOM with the need for easy customization and styling.
Open Styleable: A potential solution for styling web components
Open Styleable, a new class that can be extended by component authors, has been proposed as a potential solution for styling web components. By using this class, component authors can indicate their intention to pull down page styles or mark specific styles as pullable. This approach aims to strike a balance between providing default styles for web components and allowing page authors to override and customize those styles. However, further evaluation and feedback from developers are needed to determine the effectiveness and practicality of this solution.
Donut Scope: Leveraging media queries for component styling
Donut Scope, an alternative method for styling web components, utilizes media queries to selectively target and style elements within the light DOM and shadow DOM. By using app media queries, developers can specify which styles apply to components based on their location and relationship within the DOM. This approach offers more flexibility and allows for fine-grained control over styling. However, it does not address all use cases and further exploration is needed to determine the best approach for coordinating and managing the layers of styles within web components.
Challenges and opportunities in coordinating component and page styles
Coordinating styles between web components and the page presents several challenges and opportunities. One key question is how to provide a mechanism for specifying and interacting with different layers of styles. The concept of named layers has been suggested as a way to define and control the interaction between component and page styles. However, further investigation is required to determine the most effective approach. Additionally, engaging developers in the evaluation and testing of proposed solutions is essential to ensure practicality and usability in real-world scenarios.