Skip to content
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 overflowing text content in footer link #6519

Merged
merged 8 commits into from
Jan 12, 2024

Conversation

prajwalkulkarni
Copy link
Contributor

💫 Changelog

⭐ Fixes issue: #6460
⭐ Added text-overflow: ellipsis to show ellipsis on lengthy strings, with the addition of title attribute on the span element that shows the complete string on a tooltip on hovering the truncated string.
block property is now removed from the span element as spans are inherently inline and I feel making them behave as a block level element is semantically wrong. Instead, now we render the elements in a column-oriented flex container.
⭐ The parent container of the link string and the "Next/Previous" string is now housed by a div instead of a span

Existing UI

next-react
previous-react

Updated UI

previous-fixed-react
next-fixed-react

Add an ellipsis to overflowing text in the footer section for navigating between different references.
Fix overflowing text content in footer link
Copy link

github-actions bot commented Dec 26, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 77.39 KB (-4 B) 181.28 KB
/500 77.38 KB (-4 B) 181.27 KB
/[[...markdownPath]] 78.98 KB (-4 B) 182.87 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@prajwalkulkarni
Copy link
Contributor Author

@Huxpro could you kindly review this fix and let me know if there are any further changes to be made?

cc @gaearon @sophiebits

@@ -78,12 +78,12 @@ function FooterLink({
className="text-tertiary dark:text-tertiary-dark inline group-focus:text-link dark:group-focus:text-link-dark"
displayDirection={type === 'Previous' ? 'start' : 'end'}
/>
<span>
<span className="block no-underline text-sm tracking-wide text-secondary dark:text-secondary-dark uppercase font-bold group-focus:text-link dark:group-focus:text-link-dark group-focus:text-opacity-100">
<div className="flex flex-col overflow-hidden">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hiding the overflow, what if we update the NextLink classes above, with this:

- md:w-80
+ md:w-fit md:min-w-80

This will expand the hoverable area to fit the content, with a minimum width of 80, so you can read the full API name, but shorter names will still be 80w:

Screen.Recording.2024-01-09.at.12.24.22.PM.mov

Note: this will require either adding { minWidth: { 80: '20rem' } } to the tailwind config, or upgrading to the latest tailwind version because min-w-x was added in 3.4: https://tailwindcss.com/blog/tailwindcss-v3-4#extended-min-width-max-width-and-min-height-scales

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably update the tailwind config in this PR and do the tailwind upgrade in a separate PR.

In tailwind.config.js replace:

maxWidth: {
  xs: '21rem',
},

With:

maxWidth: {
  // add this because it should be there anyway
  ...defaultTheme.maxWidth, 
  xs: '21rem',
},
minWidth: {
  ...defaultTheme.minWidth,
  80: '20rem',
},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rickhanlonii thank you for reviewing my PR. I agree with your suggestions, but I feel there's a small caveat. If we set the width to w-fit on the NextLink directly, there'd be no upper limit, meaning extra long strings would overlap the adjacent PREVIOUS card.
case1
I could think of 2 ways to solve this:
METHOD 1 - Remove explicit width
Instead we could remove the explicit width on the NextLink and add only md:w-fit to the child div (since there's no width defined on the parent wrapper element, each hoverable card would occupy the full space, i.e, 50% of the total space available) regardless of the size of the content rendered within.
case5

case2

However, longer strings are rendered on multiple lines, so we retain the overflow-hidden.
case3

METHOD 2 - Set max width along with min width
We add min-w-80 and w-fit and along with it we also set the max-width (max-w-md), and retain the overflow property to handle the string that is longer than what the max width can accommodate.

recording.mp4

Currently, I have implemented the second approach. But I'd love to know your thoughts on this and if I should change anything further.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm not concerned about it for APIs, but for translations this could be a problem.

Can method 2 wrap at max width instead of truncating?

Copy link
Contributor Author

@prajwalkulkarni prajwalkulkarni Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that's a good idea. I tried adding a long string to the footer link with wrap instead of truncating it, and, we're able to show the complete string without loss of information(non-truncating). It is also in line with how long strings are rendered on the sidebar.
wrap2

I've implemented break-words to break-normal for wrapping the string. Below is a snapshot of a long string with no spaces in it.
wrap

Since I'm using a class sorter extension on my VSCode, a few class names in DocsFooter.tsx have been re-arranged. I hope that's not an issue. But let me know if I have to revert it.

@rickhanlonii
Copy link
Member

Looks great, thanks a ton for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants