-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: main
Are you sure you want to change the base?
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple enough!
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. |
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
Sphinx with Furo theme
|
The furo theme isn't showing properly in the sidebar, right? |
It works for me. I uploaded a GIF in my previous comment. Why are you asking? |
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. |
By the way, removing the |
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.
|
I tested this implementation on 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@ Note there is an extra pixel in the left side. I'm trying to fix that. I need to find the correct formula for |
I used JavaScript to calculate the |
src/flyout.js
Outdated
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CSS this seems like it should just be addition. If we're mixing units, we should change them all to em
so that the math is just a simple line-height + margin-bottom + margin-top + padding-bottom + padding-top
. The header height should be static, we set the font size and don't allow wrapping, so there shouldn't be guessing there either.
What value do we not know that we need to perform calculations in JS to get?
This isn't clear to me still, so maybe I'm missing something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What value do we not know that we need to perform calculations in JS to get?
I need to calculate the main.margin-bottom
's property based on the header.height
's property. How I can do that in CSS?
header.height
is not static since it will be based on the container where the theme author inject the <readthedocs-flyout>
element. How I can get that value with pure CSS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to calculate it because we should know this value.
header.height is not static since it will be based on the container where the theme author inject the element.
This doesn't seem correct. If the parent element is 10em, we get this effect if we try to fill vertical space with 100% height:
We instead want the header to be static height, and derived from font-size
. We should be able to determine the value needed for margin-bottom
just by math based on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I thought we wanted height and width to be dynamic and based on its container. If we want a fixed height, that should be easier to calculate, yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I added .container.closed { height: 2.5rem }
and kept the .container { height: auto }
so it grows accordingly when it's clicked.
I dug a little more here and I think the different behavior between our theme and furo theme is that furo uses flex for the navigation bar and we don't. This is just a guess because the they it expands and fulfill the spacing. Note that removing the hack JS code and extra CSS, the flyout grows properly on furo. The header goes to the top as it should be, instead of keeping below the main content as I showed in the other examples. However, with this code, the flyout in our theme grows to the bottom when clicked and its not shown in the page. I tried playing with flex in our theme, but I wasn't able to get it working 😢 |
Allow theme developers to define
position="inline"
to adapt the flyout to its container. It usesbottom: 0
to make it open up side, and it should probably usetop: 0
to make it open down side.readthedocs-flyout
explicitly usingposition=inline
sphinx_rtd_theme#1637position=inline
#495