Skip to content

Sidebar tab styling on narrow screens#1806

Merged
UnniKohonen merged 5 commits intomainfrom
narrow-sidebar-tabs-visibility
Aug 28, 2025
Merged

Sidebar tab styling on narrow screens#1806
UnniKohonen merged 5 commits intomainfrom
narrow-sidebar-tabs-visibility

Conversation

@UnniKohonen
Copy link
Contributor

Reasons for creating this PR

Sidebar tabs end up on two separate lines on narrow screen sizes. This PR adds an initial fix for this.

Link to relevant issue(s), if any

Description of the changes in this PR

  • Make sidebar tab padding more narrow
  • Add stylings for sidebars with 4 tabs:
    • Reduce padding more on narrow screens
    • Make last tab overflow with a fade out on narrow screens
    • Use A-Z on alphabetical tab

Addresses requirement 7.2 in #1747

Known problems or uncertainties in this PR

Checklist

  • phpUnit tests pass locally with my changes
  • I have added tests that show that the new code works, or tests are not relevant for this PR (e.g. only HTML/CSS changes)
  • The PR doesn't reduce accessibility of the front-end code (e.g. tab focus, scaling to different resolutions, use of .sr-only class, color contrast)
  • The PR doesn't introduce unintended code changes (e.g. empty lines or useless reindentation)

@UnniKohonen UnniKohonen added this to the 3.0-beta.1 milestone Aug 28, 2025
@UnniKohonen UnniKohonen requested a review from osma August 28, 2025 07:27
@UnniKohonen UnniKohonen self-assigned this Aug 28, 2025
@UnniKohonen UnniKohonen moved this to Needs review in Skosmos 3.x Backlog Aug 28, 2025
Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

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

The end result looks good, but I'm a bit worried about the amount of new CSS this introduces, and the !important rules that could cause problems for users.

I think there could be opportunities to use Boostrap utility classes (e.g. Spacing, Text, Overflow) in the HTML instead of CSS rules. I've suggested a few in the comments. Of course there might be some problem with these that aren't immediately obvious to me :) But please at least check if there are ways like this to simplify the CSS.


/* In smaller screen sizes, the last sidebar tab overflows to the right */
@media only screen and (min-width: 768px) and (max-width: 1070px) {
#sidebar-tabs.wide .nav {
Copy link
Member

Choose a reason for hiding this comment

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

Does this actually match any HTML elements? It seems to me that the .nav class is set for the same element (#sidebar-tabs), so this doesn't match its children.

In any case, I think this could be replaced with class="flex-nowrap" which is a Bootstrap utility class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed the rule but it has to be done in CSS as it is only applied on narrow screens

}
}

@media only screen and (max-width: 900px) {
Copy link
Member

Choose a reason for hiding this comment

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

Could these be replaced with Bootstrap's responsive padding utility classes such as px-sm-1 px-md-2 py-2 ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bootstrap breakpoints aren't really granular enough (md is >768px and lg >992px screen width)

}


@media only screen and (max-width: 820px) {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, use responsive padding utility classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove this because it is not really needed

}

#sidebar-tabs.wide .nav-item:last-of-type .nav-link {
justify-content: start !important;
Copy link
Member

Choose a reason for hiding this comment

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

Could this be replaced with Bootstrap's text-start utility class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rule is dependent on the screen width which the twig template doesn't know

}

#sidebar-tabs.wide .nav-link {
padding: 0.5rem 0.25rem;
Copy link
Member

Choose a reason for hiding this comment

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

Replace with Bootstrap padding classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

}

#sidebar-tabs.wide .nav-item:last-of-type {
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.

Replace with overflow-hidden class? Or is it too difficult to determine the last tab in Twig templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

<div class="sidebar-buttons">
<h2 class="visually-hidden">{{'Sidebar listing: list and traverse vocabulary contents by a criterion' | trans}}</h2>
<ul class="nav nav-tabs-no-style nav-justified" id="sidebar-tabs" role="tablist">
<ul class="nav nav-tabs-no-style nav-justified{% if vocab.config.sidebarViews | length == 4 and vocab.config.showDeprecatedChanges %} wide{% endif %}" id="sidebar-tabs" role="tablist">
Copy link
Member

Choose a reason for hiding this comment

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

Could we change the condition to >= 4 just in case it's later possible to add more than 4 tabs?

<ul class="nav nav-tabs-no-style nav-justified{% if vocab.config.sidebarViews | length == 4 and vocab.config.showDeprecatedChanges %} wide{% endif %}" id="sidebar-tabs" role="tablist">
{% for view in vocab.config.sidebarViews %}
{% if view == 'alphabetical' %} {% set view_trans_text = 'Alpha-nav' %}
{% if view == 'alphabetical' %} {% set view_trans_text = (vocab.config.sidebarViews | length == 4) ? 'A-Z' : 'Alpha-nav' %}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, >= 4 would be more future-proof

align-items: center;
justify-content: center;
transition: none;
padding: 0.5rem;
Copy link
Member

Choose a reason for hiding this comment

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

Use Bootstrap utility class p-2 or something along those lines?

Copy link
Member

@osma osma left a comment

Choose a reason for hiding this comment

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

Please merge after considering my suggestions

@sonarqubecloud
Copy link

@UnniKohonen UnniKohonen merged commit 5f34aa8 into main Aug 28, 2025
12 checks passed
@github-project-automation github-project-automation bot moved this from Needs review to Issue/PR closed in Skosmos 3.x Backlog Aug 28, 2025
@UnniKohonen UnniKohonen deleted the narrow-sidebar-tabs-visibility branch August 28, 2025 09:50
@UnniKohonen UnniKohonen moved this from Issue/PR closed to Done (verified in test.dev.finto.fi, set Milestone 3.0 for both issue & PR) in Skosmos 3.x Backlog Aug 28, 2025
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.

2 participants