Using the :disabled pseudo-class in Chrome prevents CSS Shadow Parts Selector ::part() from working in combination

In the Chrome browser, there seems to be an issue with the pseudo-element selector ::part() and the :disabled pseudo-class not functioning correctly. Surprisingly, Firefox handles this without any problems.

Take a look at the sample code provided below. You'll notice that only in Firefox, the disabled button showcases a yellow background color.

customElements.define('my-button', class extends HTMLElement {
  constructor() {
    super();
    const shadowRoot = this.attachShadow({mode: 'open'});
    shadowRoot.innerHTML = `
      <button disabled part="button">Button in Shadow DOM</button>
    `;
  }
});
my-button::part(button) {
  color: gray;
}

my-button::part(button):disabled {
  background-color: yellow;
}
<my-button></my-button>

Is this disparity between Chrome and Firefox a bug or simply the intended behavior?

Answer №1

According to the specifications:

The ::part() pseudo-element is capable of accepting additional pseudo-classes after it, such as x-button::part(label):hover, but it will not match structural pseudo-classes or any other pseudo-classes based on tree information rather than local element information.

Furthermore, the ::part() pseudo-element can also receive additional pseudo-elements after it, like x-button::part(label)::before, without matching additional ::part()s.

Since :disabled is not considered structural, this issue appears to be a bug specific to Chrome. Upon investigation, I came across a relevant bug report in the Chromium bug tracker: Bug Report Link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Graphical Interface for an HTTPAPI

After successfully building a REST API in Node.js using Express that includes queue functionalities, my next goal is to develop a web interface for this API. As a newcomer to JavaScript and Node.js, I would greatly appreciate any advice or guidance on ho ...

Create a div element containing a captivating background image that automatically scales to fit any browser window

Currently, I am facing a challenge with scaling background images within a shared div (framework) so that they can resize along with the browser. I have searched for solutions involving Javascript, but none seem to address my specific case. Any assistance ...

Accurate timing of brief image displays with JavaScript

I am embarking on an innovative online psychology experiment using JavaScript to explore the human ability to swiftly recognize images. This study utilizes the RSVP (Rapid Serial Visual Presentation) paradigm, a prevalent method in psychophysics that isola ...

Unable to add a review to the user profile using Node.js (Express) and MongoDB (Mongoose)

I am encountering an issue when it comes to adding reviews for a user. After creating a review for a user, only the ID is displayed, but not the text or author or any other properties. I would appreciate any insights on this matter. Below are my schemas a ...

Exporting Textures with Custom Offsets to GLTF from Three.js Scene

UPDATE: I was initially puzzled about exporting to obj and mtl formats, but then I stumbled upon the GLTFExporter.js in three.js which allowed me to successfully extract both the geometry and texture from my project. However, a new challenge arose with t ...

The concept of JavaScript function aliasing appears to be ineffective

After coming across this specific question, I decided to experiment with the alias method rather than using the function-wrapper method. Unfortunately, I faced issues getting it to function properly in both Firefox 3 and 3.5beta4, as well as in Google Chro ...

Combining Entities Using Immutable JavaScript

Currently utilizing React, Redux, and Immutable. I have a question about merging a plain JavaScript object into an Immutable Map object. Importing Immutable.js: import { List as iList, Map as iMap } from "immutable"; The content of action.paylo ...

JavaScript: What's the best way to update the URL in the address bar without triggering a page refresh?

Similar Question: How can I use JavaScript to update the browser URL without reloading the page? I've observed websites like GMail and GrooveShark altering the URL in the address bar without having to refresh the entire page. Based on my understa ...

Embedding a pop-up window in PHP script

My current task involves creating a table where clicking on an ID opens a popup window with a menu for changing row values and adding comments. However, I am facing difficulty in generating a link for each row: foreach ($results as $row) { // Each $row is ...

Toggle on and off using a checkbox feature in conjunction with the straightforward form gem

Seeking assistance in toggling an action using a checkbox on a post form. Not well-versed in javascript or JQuery. Struggling with this task while working alone. If anyone can provide guidance, it would be greatly appreciated! Using Rails 4.2.8 an ...

"Deleting a line from a text file in PHP with a predetermined format: A step-by-step guide

I am facing a situation where I need to manipulate a CSS file through PHP. The CSS file contains the following properties: #firstdiv { width:100%; height:200px; } #seconddiv { width:80%; height:70px; } #thirddiv { width:80%; height:70px; } #firstdiv { col ...

Creating HTML code using PHP to display two tables next to each other

My goal is to display two tables side by side in an HTML table, each ordered by a different column. I attempted this using the following code: <tbody> <td> <?php require_once "db_data.php"; $bids_results = $mysqli-& ...

The key you entered in local storage was not defined and the value associated with

Having an issue with my HTML signup form where the key is showing as undefined (email should be the key) and the value displays as [object Object]. Any help in resolving this problem would be greatly appreciated. Thank you. <!DOCTYPE html> <html& ...

Storing a portion of AJAX response as a PHP variable

Is there a way to store data received through an AJAX response in a PHP variable? I want to take the value of $('#attempts_taken').val(data[11]); and save it as a PHP variable. Any help would be great! <script type="text/javascript> $(do ...

Issues with importing Three.js as a module - encountering an Uncaught SyntaxError:

I am currently delving into the world of three.js and working on my first project. I am following the example code provided on the three.js website. Everything runs smoothly when I have three.js stored in a folder like: js/ directory However, I am enco ...

What is the best way to include a css file in a react component directly as raw text?

What am I attempting to achieve? I have a WYSIWYG editor that allows me to create small HTML pages, and then it sends a request to save the page in the backend. Now, I want to include CSS in the request to apply all styles from the parent page (the one co ...

Retrieving values of numerous Control IDs within ASP.net Listview and transferring them to JavaScript

I am working on a project where I have multiple labels within a listview control on an ASP.net page. My goal is to access the values of these labels in JavaScript in order to display specific data for each label when the user hovers over it with a mouse-ov ...

Struggling with updating a user in MongoDB using findOneAndUpdate and encountering a frustrating internal server error 500?

Presently, I am in the process of developing an API that is designed to update the current user in mongoDB based on the data provided in the request. However, whenever I execute findOneAndUpdate(), I encounter a 500 internal server error. (I will outline ...

Creating a customized greeting message using discord.js

I've been working on creating a Discord bot using discord.js, and I'm trying to figure out how to make the bot send a welcome message when a new member joins the server and opens a chat with the bot. The message should be something like "Hi there ...

How can the parent Flexbox in a nested Flexbox shrink and remain at the top, wrapping to the next line only when the available space is insufficient for display?

What is the best way to ensure that box 1, 2, and 3 stay on the right of box A in a desktop browser, but shift below box A if there isn't enough space (e.g. in a smartphone browser)? I am open to solutions using either Bootstrap 4 or 5. https://i.sst ...