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

Flyout: define position="inline" #500

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

Conversation

humitos
Copy link
Member

@humitos humitos commented Jan 16, 2025

Allow theme developers to define position="inline" to adapt the flyout to its container. It uses bottom: 0 to make it open up side, and it should probably use top: 0 to make it open down side.

Peek 2025-01-16 15-44

Allow theme developers to define `position="inline"` to adapt the flyout to its
container. It uses `bottom: 0` to make it open up side, and it should probably
use `top: 0` to make it open down side.
@humitos humitos requested a review from a team as a code owner January 16, 2025 14:32
@humitos humitos requested a review from agjohnson January 16, 2025 14:32
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Simple enough!

src/flyout.js Show resolved Hide resolved
src/flyout.css Outdated Show resolved Hide resolved
src/flyout.css Outdated Show resolved Hide resolved
@agjohnson
Copy link
Contributor

Here is a very rough example of inline positioning: #501

It doesn't take much more but there is some cleanup required and working into themes might require experimenting with overflow clipping on the theme elements.

agjohnson and others added 2 commits January 20, 2025 14:19
Here is a quick example of using inline positioning. I've reused
`top-left` position to indicate "downward expanding menu" but this could
be something more explicit. It would be nice as `position="inline down"`
perhaps.

There are two basic examples, one truly inline and one flyout inside a
mock sidebar menu -- just to illustrate a theme maintainer nesting the
flyout element inside another element.

The tricky part here is making the `main` menu "float" over other
content, and we use `overflow: visible` and absolute positioning to
allow content to reflow around the element.

There are some fixes required here: too narrow of a parent clips the
collapsed menu, we probably want a max width on the popup menu (keeping
the collapsed menu width 100% (this is to fill the parent element).



https://github.com/user-attachments/assets/413d7c03-38d3-48e0-a88a-4cf53cc8dd92
@humitos
Copy link
Member Author

humitos commented Jan 20, 2025

This is an example of what I currently have. It shows the current default floating bottom right position, then the bottom inline position and finally the top inline position.

I think we should probably change bottom and top by down and up classes, meaning what's the direction the flyout opens.

Peek 2025-01-20 14-21

@humitos humitos requested a review from agjohnson January 20, 2025 13:33
@humitos
Copy link
Member Author

humitos commented Jan 20, 2025

Read the Docs theme

Peek 2025-01-20 15-20

@humitos
Copy link
Member Author

humitos commented Jan 20, 2025

Sphinx with Furo theme

Peek 2025-01-20 16-35

@ericholscher
Copy link
Member

The furo theme isn't showing properly in the sidebar, right?

@humitos
Copy link
Member Author

humitos commented Jan 20, 2025

It works for me. I uploaded a GIF in my previous comment. Why are you asking?

@ericholscher
Copy link
Member

ericholscher commented Jan 20, 2025

It's overlapping? The red line is the sidebar divider, right?

image

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

Ah, yes. I think that is responsibility of the theme author, not the flyout itself -- but I'm not 100% sure. I understand the flyout container has to be adjusted with CSS properties to make the flyout behave as expected.

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

By the way, removing the padding: 0 10px from .container.inline makes the flyout to match the sidebar size on Furo. However, it doesn't look as we want because the logo and the caret has no padding and touch the borders. Also, it doesn't cover all the width of the sidebar on Read the Docs theme.

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

I was able to fix the in Furo adding CSS in the flyout container without changing anything in our code. So, this is responsibility of the theme developer.

Peek 2025-01-21 10-43

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

I tested this implementation on insipid theme as well.

Note that it works fine, it just requires adding some specific style to the flyout container already defined in the theme. These are the override changes used in test-builds: readthedocs/test-builds@insipid-theme?expand=1#diff-d3eab869c9

Peek 2025-01-21 12-19

Note there is an extra pixel in the left side. I'm trying to fix that. I need to find the correct formula for .container.inline main { margin-left: calc(var(--addons-flyout-font-size) - 1.3rem )} cc @agjohnson

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

Boom! I was able to find the CSS combination that works 👍🏼

Example for Insipid, Read the Docs and Furo themes.

Peek 2025-01-21 12-36

@humitos
Copy link
Member Author

humitos commented Jan 21, 2025

I used JavaScript to calculate the main.margin-bottom's property based on the header.height's property because I think there is no way in CSS to use a value based on another element's property. This code allowed me to avoid issue with extra pixels when clicking on the flyout due to the height of the header -- which could vary depending on the theme.

);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So we should always avoid doing anything with JS, especially with Element.style. What this property does is add inline style="" attribute to the element, which causes trouble with secure CSP rulesets and causes problems when users try to override our styles.

What value do we not know that we need to perform calculations in JS to get?

Copy link
Member Author

Choose a reason for hiding this comment

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

I know, but I did it in JS to show this is possible at least.

I wrote what I need to do in #500 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know how to do that with pure CSS? 🤔

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

Successfully merging this pull request may close these issues.

Flyout: investigate position=inline
3 participants