docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Long labels in the sidebar do not display correctly

Open shipswake opened this issue 1 year ago β€’ 13 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

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

Description

I have sidebar items auto generated with @grapql-markdown Some of the labels in the sidebar are very long and cannot be fully seen

image

It would be very helpful for the long labels to be truncated with an ellipse and a tooltip added so the full label can be seen on hover

Reproducible demo

No response

Steps to reproduce

Create a new Docusaurus site Create content which has very long labels in the sidebar

The labels are hidden behind the page view

Expected behavior

Would like to see the labels truncated with an ellipse and a tooltip displayed on hover of the label

Actual behavior

The long labels in the sidebar are hidden by the page

Your environment

  • Public source code: none
  • Public site URL: none
  • Docusaurus version used: latest
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Edge
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10

Self-service

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

shipswake avatar Sep 27 '24 15:09 shipswake

Please assign this issue to me. I would be very happy to work on it.

PranavKeshav24 avatar Oct 01 '24 11:10 PranavKeshav24

@PranavKeshav24 you can already start working on it. We only assign an issue after you open a draft PR showing you are capable of solving the problem.

slorber avatar Oct 03 '24 09:10 slorber

cc @pwizla I remember seeing Strapi docs also truncating sidebar labels, maybe that could serve as an inspiration for the CSS to use to solve this

https://docs.strapi.io/dev-docs/api/document-service

CleanShot 2024-10-03 at 11 35 53

slorber avatar Oct 03 '24 09:10 slorber

Thank you for the heads-up, @slorber! This comment is timely as I'm completely reworking the style of Strapi docs. πŸ˜„

@PranavKeshav24 Here's what did the trick for us, if you simply want to truncate the content: https://github.com/strapi/documentation/blob/main/docusaurus/src/scss/sidebar.scss#L139-L140 (and you might not even need the white-space property, we have it because we sometimes add labels to the sidebar items).

pwizla avatar Oct 03 '24 09:10 pwizla

@shipswake could you be more specific on how to reproduce the issue? I was not able to reproduce the bug

Sanjoy-droid avatar Oct 04 '24 13:10 Sanjoy-droid

From above: image

If you have a very long label in the sidebar the label will be hidden behind the page

The label should be truncated with an ellipsis and the full label readable in a tooltip when hovering over the label.

Here is the discussion: https://github.com/facebook/docusaurus/discussions/10529

shipswake avatar Oct 04 '24 14:10 shipswake

Thank you for the heads-up, @slorber! This comment is timely as I'm completely reworking the style of Strapi docs. πŸ˜„

@PranavKeshav24 Here's what did the trick for us, if you simply want to truncate the content: https://github.com/strapi/documentation/blob/main/docusaurus/src/scss/sidebar.scss#L139-L140 (and you might not even need the white-space property, we have it because we sometimes add labels to the sidebar items).

Thank you so much for sharing that. πŸ˜„

PranavKeshav24 avatar Oct 07 '24 13:10 PranavKeshav24

/assign

Shrasingh avatar Oct 11 '24 12:10 Shrasingh

Have you read the Contributing Guidelines on issues?

Prerequisites

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

Description

I have sidebar items auto generated with @grapql-markdown Some of the labels in the sidebar are very long and cannot be fully seen

image

It would be very helpful for the long labels to be truncated with an ellipse and a tooltip added so the full label can be seen on hover

Reproducible demo

No response

Steps to reproduce

Create a new Docusaurus site Create content which has very long labels in the sidebar

The labels are hidden behind the page view

Expected behavior

Would like to see the labels truncated with an ellipse and a tooltip displayed on hover of the label

Actual behavior

The long labels in the sidebar are hidden by the page

Your environment

  • Public source code: none
  • Public site URL: none
  • Docusaurus version used: latest
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Edge
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10

Self-service

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

could you please provide a demo or more clarity to reproduce this issue,

PrinceACS avatar Oct 12 '24 09:10 PrinceACS

Please assign this issue to me.

omchaudhary007 avatar Oct 13 '24 06:10 omchaudhary007

/assign

omchaudhary007 avatar Oct 13 '24 06:10 omchaudhary007

Is this issue solved or anyone working on this ?

YoosufAathil avatar Oct 14 '24 12:10 YoosufAathil

is this issue fixed?

krVatsal avatar Oct 14 '24 14:10 krVatsal

Any update on this?

shipswake avatar Oct 29 '24 18:10 shipswake

Any update is visible in this thread. No PR means no progress.

Josh-Cena avatar Oct 29 '24 19:10 Josh-Cena

Typically, the way this is done is by making the anchor tag a block element (display: block) and then apply the CSS properties to show ellipsis when the text overflows https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow

The CSS properties to be set are: white-space(nowrap), overflow(hidden), and text-overflow(ellipsis): which is what @pwizla has pointed out above.πŸ‘

vipulbhasin23 avatar Jul 17 '25 13:07 vipulbhasin23

Any progress on this?

I already raised a question about this topic in a previous discussion, but now it affects me again, in a site that includes TypeScript Reference pages:

Image

I know that table cells can be configured to cut long texts and show ellipses (with your help I fixed the custom tables in my pages), but sidebars are a bit more complicated and I could not fix them with local CSS patches.

Can we so something to make the sidebar look better? With the current layout I doubt we'll win any beauty contest... :-(

ilg-ul avatar Jul 21 '25 11:07 ilg-ul

@slorber, any idea how to patch the CSSs for the sidebar to cut long labels and show ellipses?

ilg-ul avatar Jul 22 '25 19:07 ilg-ul

For the records, in case someone else will encounter this problem.

I fixed it by adding

  • className: doxyEllipsis to the sidebar entries that require ellipsis
  • the following CSS definitions:
.doxyEllipsis .menu__list-item {
  overflow: hidden;         /* Hide overflowing content */
}

.doxyEllipsis .menu__link {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: block !important; /* Ensure it's a block element for ellipsis to work */
  margin-right: 0px;
}

.doxyEllipsis .menu__caret {
  flex-shrink: 0;           /* Prevent the button from shrinking */
  margin-left: 4px;         /* Add some space between text and button */
}

An example how this looks is the Classes -> Hierarchy entry in the Β΅Test++ website:

  • https://micro-os-plus.github.io/micro-test-plus-xpack/docs/api/indices/classes/classes/

ilg-ul avatar Jul 29 '25 18:07 ilg-ul

Going to be fixed in https://github.com/facebook/docusaurus/pull/11356

I choose line-clamp: 2 over the methods above since it's widely supported CSS now (under -webkit prefix though), and looks like a reasonable default to show 2 lines for most sites. But you can easily override that value.

We can clamp properly both docs/links and expandable category items (with/without generated index). Hover shows a tooltip thanks to title (not perfect for accessibility, but good enough).

Image

slorber avatar Jul 31 '25 10:07 slorber

It looks definitely better, thank you!

ilg-ul avatar Aug 02 '25 06:08 ilg-ul