Skip to content

Enhancements for dropdowns: animations, open at initial state, and chevron indicators #675

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

agriyakhetarpal
Copy link
Contributor

@agriyakhetarpal agriyakhetarpal commented May 14, 2025

Description

This PR modifies the dropdown shortcode to add three new features, in order to establish feature parity with the dropdowns from the PyData Sphinx Theme and the sphinx-design projects. This was also discussed in #477 (comment), and should resolve that part of the conversation. Also, this PR is an aftermath of #471.

In particular, the features added here are as follows:

  • An "open" dropdown: the option to leave the dropdown open at initial load, i.e., with the contents expanded instead of collapsed
  • Chevron indicators: these are now displayed at the end of the dropdown's title container when the dropdown has been expanded or is in its collapsed state, and are animated, and there is also a choice between
  • Animations for the chevron indicators and for how the content is displayed (fade-in, fade-in-slide-down) have been added, based on the corresponding option for the directive

In addition to this, I've added several more examples to the shortcode's docs: a success dropdown, a warning one, a danger one, a multi-line example, one with code, and lastly, a nested dropdown.

I've checked for any accessibility issues/implications, and I think this should be fine; I've closely followed the PST/SD implementation(s), and the chevrons here work similarly.

Copy link

netlify bot commented May 14, 2025

Deploy Preview for scientific-python-hugo-theme ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e462173
🔍 Latest deploy log https://app.netlify.com/projects/scientific-python-hugo-theme/deploys/683ee6b3df27e90008e94871
😎 Deploy Preview https://deploy-preview-675--scientific-python-hugo-theme.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 88
Accessibility: 100
Best Practices: 100
SEO: 91
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@agriyakhetarpal agriyakhetarpal force-pushed the dropdown-enhancements branch from 8802455 to f15829b Compare May 14, 2025 05:22
@agriyakhetarpal agriyakhetarpal changed the title [DRAFT]: Enhancements for dropdowns: animations, open at initial state, and chevron indicators Enhancements for dropdowns: animations, open at initial state, and chevron indicators May 14, 2025
@agriyakhetarpal agriyakhetarpal marked this pull request as ready for review May 14, 2025 05:36
@agriyakhetarpal agriyakhetarpal mentioned this pull request May 14, 2025
6 tasks
@smeragoel
Copy link

Thanks for working on this @agriyakhetarpal! I think the addition of the chevron indicators would help users in recognising that the dropdowns are expandable 😄

I'm wondering if we can change the speed of the chevron animation on hover? From what I can see, the chevron has a fade-in animation, but the background colour change seems to be quicker. I think it would be nice if both animations ended at the same time. I think this is also the case in the PST dropdown animations.

This is a small nitpick though, overall I think the improvements are great. Thanks again!

@agriyakhetarpal
Copy link
Contributor Author

I appreciate the feedback, @smeragoel! You are right, there is a slight delay between the darkening of the dropdown bar background on hover and the scaling of the chevrons kicking in. However, this is because the PST implementation in https://pydata-sphinx-theme.readthedocs.io/en/stable/user_guide/web-components.html#dropdowns does not include animations; the dropdown bar's background changes colour and the chevrons do not animate when transform: scale(1.1) is applied, both of them instead scaling instantaneously.

I've gone ahead and implemented your suggestion with the above commit to match PST – the chevrons should no longer scale when hovering and thus end at the same time as the dropdown's background colour change. Could you PTAL when it is convenient for you?


To be completely honest: I did notice this difference when working on the changes here, and I've quite come to like the slight deviation that I've made from PST – I feel that it's nice that the chevrons here also animate on hovering rather than abruptly scaling in size without an animation. However, I understand that I would be biased here as I'm familiar with my PR more :)

Could you educate me about any accessibility concerns that may arise with the previous case (i.e., before this commit) as I may not be aware of them? Thank you!

@stefanv stefanv added the type: Enhancement New feature or request label Jun 3, 2025
@stefanv
Copy link
Member

stefanv commented Jun 3, 2025

Looks good to me, thanks @agriyakhetarpal!

Could we make the chevron animation go in the other direction? It feels to me like, if the content scrolls down the chevron should rotate clockwise. This is already true for the sideways chevron, but not the up-down one.

Just my aesthetic feeling :)

@agriyakhetarpal
Copy link
Contributor Author

Looks good to me, thanks @agriyakhetarpal!

Could we make the chevron animation go in the other direction? It feels to me like, if the content scrolls down the chevron should rotate clockwise. This is already true for the sideways chevron, but not the up-down one.

Just my aesthetic feeling :)

Yes, certainly, I agree. This is also the case with the GitHub PR checks we can see above the comment box, they rotate clockwise in a 180-degree rotation and I like them too :)

@agriyakhetarpal
Copy link
Contributor Author

agriyakhetarpal commented Jun 3, 2025

Actually, wait, the down-up chevron does rotate clockwise from down to up, doesn't it? Do you mean it should rotate clockwise from up to down as well, i.e., to complete a full-circle rotation in one close/open of a dropdown, or would you like it if it were to first rotate anti-clockwise from down to up + then clockwise from up to down (like as the GitHub PR checks one above)?

I ask this because I have no strong opinion here; the last example in https://sphinx-design.readthedocs.io/en/pydata-theme/dropdowns.html#more-examples is the down-up case, and it does not have an animation at all. I chose to deviate from it and add an animation as I felt that it was better to have one. :)

@stefanv
Copy link
Member

stefanv commented Jun 3, 2025

The GitHub directions feel intuitive to me, so I'd mimic that.

@agriyakhetarpal
Copy link
Contributor Author

One thing we should also address here before merging: the FontAwesome icons can take their due time to load on throttled networks based on the limited simulations I performed and on what I noticed with several hard refreshes (without caches) – the dropdown bars will show up first and the chevrons way later on a slow network. Maybe it makes sense to vendor these specific icons? I think PST is doing this, too.

@stefanv
Copy link
Member

stefanv commented Jun 3, 2025

Yes, either that, or you may be able to use unicode chevrons. They should look good enough.

@agriyakhetarpal
Copy link
Contributor Author

agriyakhetarpal commented Jun 3, 2025

I addressed the animation changes in the commit above; it should now resemble the GitHub interface.

I tried the Unicode chevron https://www.compart.com/en/unicode/U+276F, which looks like this: ❯

However, it's not as nice (and not the same as the FontAwesome ones either), and no available rotated equivalent retains the same shape. Vendoring should be the preferred approach here, for parity with PST.

Edit: argh, okay, so it looks like PST is using webpack to do this: https://github.com/pydata/pydata-sphinx-theme/blob/eef26c8c4c80b23e846dbcd2ebc9804093341f8c/webpack.config.js. We could vendor only the specific chevron icons for their inline SVGs, but I don't want to leave things in an inconsistent state where we vendor two symbols and not the rest of them. I think it makes sense for us to go down the webpack pathway as well, and I know that there were a few other themes that were doing it for the same reasons as PST – I can take this on in a subsequent PR, not here :)

Copy link
Contributor Author

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

All done (for now). This is ready for another look! Here is a self-review for some explanations.

Comment on lines -8 to -10
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My text editor warns that these attributes are non-standard and should be avoided, and user-select is baseline already. The same warnings occur in a few other places below, and I removed the browser-engine-specific styling there as well.

Comment on lines +145 to +159
&:not([open]) > .sd-summary-title:hover .sd-summary-chevron-right i {
transform: scale(1.1);
}

&:not([open]) > .sd-summary-title:hover .sd-summary-chevron-down i {
transform: scale(1.1);
}

&[open] > .sd-summary-title:hover .sd-summary-chevron-right i {
transform: rotate(90deg) scale(1.1);
}

&[open] > .sd-summary-title:hover .sd-summary-chevron-down i {
transform: rotate(-180deg) scale(1.1);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the earlier commit I pushed today, I changed this to .sd-summary-title:hover as we want to increase the chevron sizes only when hovering over the dropdown bars and not when hovering over the content inside them (this is the same as PST).

In particular, these lines address the cases where you hover over the chevrons and click on them – we don't want the chevrons to transition from a 1.1x scale to a 1.0x scale while rotating and then back to a 1.1x scale, but rather stay at a 1.1x scale throughout the transition.

Comment on lines -93 to -94
-moz-animation: sd-fade-in 0.5s ease-in-out;
-webkit-animation: sd-fade-in 0.5s ease-in-out;
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 – these are non-standard attributes and are best avoided. I can also clean these up from everywhere in a separate PR and reduce the diff here if you want me to.

Comment on lines +177 to +179
<span class="sd-summary-state-marker {{ $chevronClass }}">
<i class="fas {{ $chevronIcon }}"></i>
</span>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.sd-summary-state-marker is a separate element that makes it easier for us to style where the chevrons are placed (at the end of the dropdown bars).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants