Skip to content

DocSearch styles don't respect navbar.style: dark #11542

@erickzhao

Description

@erickzhao

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

After upgrading to Docusaurus 3.9,

The root cause of this issue is that the upstream --docsearch-* CSS variables apply their dark/light mode based on the root site's data-theme attribute.

Ideally, we would be able to apply html[data-theme='dark'] variables while the search box is wrapped in the .navbar--dark class, but I don't think this is possible given the structure of the CSS (variables are being applied upstream at @docsearch/css).

Potential fixes:

  • Duplicate the dark mode CSS variables for components within the .navbar--dark class.
  • Update variables upstream in @docsearch/css so we don't need to manually copy these values to the previous CSS rule.

Reproducible demo

https://codesandbox.io/p/devbox/xenodochial-ritchie-tk6g7f?file=%2Fdocusaurus.config.js

Steps to reproduce

  1. Enable Algolia search by setting themeConfig.algolia in your Docusaurus config.
  2. Set themeConfig.navbar.style: dark in your Docusaurus config.
const config = {
  themeConfig: {
    algolia: { /** some algolia configuration */ },
    navbar: {
       style: 'dark'
    }
  }
}

Expected behavior

Dark mode colour scheme in the navbar should apply regardless of light/dark mode value.

Actual behavior

Light mode colours apply, leading to limited readability in the search box.

Image

Your environment

  • Docusaurus version used: 3.9.2
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 142
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS Sequoia

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionexternalThis issue is caused by an external dependency and not Docusaurus.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions