-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(theme-classic): avoid rendering empty search box container #7990
Conversation
Hi @drizzlesconsin! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx
Outdated
Show resolved
Hide resolved
packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Just pending the CLA
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, this doesn't work. If you check locally, the empty container is still rendered. This is because the <SearchBar />
element is always there; it just sometimes returns null
(which is not the same as a literal null
children). We need a better solution.
That can only be determined by the |
}: Props): JSX.Element { | ||
}: Props): JSX.Element | null { | ||
const {siteConfig} = useDocusaurusContext(); | ||
if (!siteConfig.themeConfig?.algolia) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not work for non-official search plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
em...Let's see if there's another way.
The problem is that we are trying to add an implicit search bar by default (ie not configured through What I suggest is that in 3.0 we can do a breaking change:
Another possible solution: using CSS In the future, we should allow search plugin authors to register their own Navbar item components. They would be able to create a Do you still want to work on this? (considering you opened a Fixing it just for yourself should be possible with swizzling or custom CSS |
Is it possible to use this method here? children.type() === null I read: |
There's no good solution to this problem in React. I don't want to introduce hacky workarounds in our theme when there's a clear elegant solution: be explicit and avoid rendering this parent search component in the first place |
Looks like it can only be hack with CSS. |
What about using the named Noop component and then before rendering SearchBar, checking the value of |
will be fixed in #9385 |
Pre-flight checklist
Motivation
https://stackblitz.com/github/facebook/docusaurus/tree/starter
The search box should not be displayed when the search function is not enabled.
Test Plan
Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs