prefer-data-theme-docsearch-overrides
Prefer explicit site data-theme selectors over .navbar--dark when overriding DocSearch styles.
Targeted pattern scopeโ
This rule targets selectors that do all of the following at the same time:
- match
.navbar--dark - target a DocSearch class such as
.DocSearch-Buttonor.DocSearch-Modal - do not include any explicit
[data-theme=...]scope
The rule is intentionally narrow. It does not report general .navbar--dark styling, and it does not report DocSearch selectors that are already scoped by the site's actual color mode.
What this rule reportsโ
This rule reports DocSearch overrides that use .navbar--dark as a proxy for site color mode.
Why this rule existsโ
In Docusaurus, the site's active light/dark mode is exposed on the root HTML element through the data-theme attribute.
DocSearch styling also follows the root site's color mode. That means .navbar--dark is not a reliable substitute for the site's active theme when you customize DocSearch UI pieces.
Using .navbar--dark for DocSearch dark-mode overrides can make the search UI drift away from the actual site color mode and produce unreadable combinations.
โ Incorrectโ
.navbar--dark .DocSearch-Button {
color: white;
background: rgb(20 20 20 / 80%);
}
โ Correctโ
[data-theme="dark"] .DocSearch-Button {
color: white;
background: rgb(20 20 20 / 80%);
}
Behavior and migration notesโ
- This rule only checks selectors that touch DocSearch classes.
- It does not autofix because converting
.navbar--darkselectors into correct site-leveldata-themeselectors requires author intent. - If you truly want DocSearch to follow navbar styling instead of site color mode, disable this rule for that project.
Additional examplesโ
โ Correct โ explicit light-mode scopeโ
[data-theme="light"] .DocSearch-Button {
color: var(--ifm-color-emphasis-700);
}
โ Correct โ non-DocSearch navbar overrideโ
.navbar--dark .searchLabel {
color: white;
}
Stylelint config exampleโ
import { docusaurusPluginConfigs } from "stylelint-plugin-docusaurus";
export default {
...docusaurusPluginConfigs["docusaurus-all"],
rules: {
...docusaurusPluginConfigs["docusaurus-all"].rules,
"docusaurus/prefer-data-theme-docsearch-overrides": true,
},
};
When not to use itโ
Disable this rule if your site intentionally keeps DocSearch visually tied to a permanently dark navbar style instead of the site's actual data-theme value.
Package documentationโ
Docusaurus package documentation:
Rule catalog ID: R005