Skip to content

Make the theme responsive - #46

Merged
JulienPalard merged 24 commits into
python:masterfrom
obulat:master
May 7, 2021
Merged

JulienPalard merged 24 commits into
python:masterfrom
obulat:master

Conversation

@obulat

@obulat obulat commented May 19, 2020

Copy link
Copy Markdown
Contributor

I have been reading on my phone a lot lately, and was disappointed by the fact that I couldn't read python docs: the fonts are too small, and, if I try to zoom in, the text doesn't fit on the page, so I have to swipe to see the whole line.

This is my attempt to add responsiveness to python docs theme, fixing #30.

On screen widths smaller than 900 px, it:

  • adds a mobile navigation bar with a 'hamburger' menu button, Python version switcher and a search box.

  • adds a sliding menu that opens when 'hamburger' menu button is clicked. Menu contains language switching input and contents.

  • removes the related bars

  • removes the sidebar.

Screenshot with menu closed:
Responsive  Menu closed Galaxy S5
Screenshot with menu open:
Responsive  Menu open Galaxy S5

Problems that need to be solved:

  • Normally, the mobile navigation bar should be placed in the header block of the layout, but python.org layout completely overrides it, so I added it in the body_tag block. To solve this, I would need to add changes to that code.

  • I placed the switchers and other items on the menus as seemed logical to me, but feedback from the community is essential on this.

  • I added a javascript file to open/close sidebar in a separate file. I could also add it into the layout file, but ideally all js files should be combined and minified.

@septatrix septatrix left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall a great idea and I would also really like a responsive theme though there seem to be some unrelated changes and implementation details which should be discussed

Comment thread python_docs_theme/layout.html
Comment thread python_docs_theme/layout.html Outdated
Comment thread python_docs_theme/layout.html Outdated
Comment thread python_docs_theme/static/pydoctheme.css Outdated
Comment thread python_docs_theme/static/pydoctheme.css Outdated
Comment thread python_docs_theme/static/pydoctheme.css Outdated
Comment thread python_docs_theme/static/pydoctheme.css Outdated
Comment thread python_docs_theme/theme.conf Outdated
Comment on lines +2 to +22
document.addEventListener('DOMContentLoaded', function () {
const toggler = document.querySelector('.toggler');
const sideMenu = document.querySelector('.menu-wrapper');
const doc = document.querySelector('.document');
function closeMenu() {
sideMenu.classList.remove('open');
toggler.checked = false;
}
toggler.addEventListener('change', function (e) {
if (toggler.checked) {
sideMenu.classList.add('open');
} else {
closeMenu();
}
});
doc.addEventListener('click', function () {
if (toggler.checked) {
closeMenu();
}
})
}) No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

By moving the checkbox up in the dom tree it may be possible to implement this using only javascript and make it more accessible for people without javascript

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I replaced the checkbox with a button. Is this better for people without javascript?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What I would have done is move the input as a checkbox directly next to the sidebar, reference it in the label via id and apply the styles based on whether the checkbox is checked or not. I may have time tomorrow to create a PR on your fork repo if you want to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have done it like this at first (checkbox input and applying styles based on :checked property). Then I was checking for accessibility and found this article which shows that a button as menu opener has some advantages regarding accessibility: namely, it is easier to set up keyboard handling. On the other hand, I just realized that people probably don't use keyboard for navigation on mobile, and it is more important to set up No-script solution than keyboard navigation on mobile.
Also, I looked at other documentation sites: readthedocs theme and VueJS docs, and their hamburger menu doesn't work without javascript.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In addition if you follow this guide you also get a working css only solution with added accesibility using javascript

@obulat

obulat commented Jun 14, 2020

Copy link
Copy Markdown
Contributor Author

Thank you for your review, @septatrix !
I don't have a reliable internet connection at the moment, but will try to address your comments as soon as possible. Overall, I have tried to make the theme accessible as well as responsive, that's the reason for some label handling. Also, I tried to use only Vanilla javascript to make it easier to remove jquery dependency in the future.

I would also like to have your feedback on the content for the mobile version. For example, the top navbar on mobile: Do you think logo, version switcher and searchbox are what should be there, or do we need to add/ remove something?

Also, the relbar is completely removed, but I thought that it might be a good idea to add it at the bottom, without the searchbox, though.

- Remove unnecessary `show` call for searchbox.
- Remove `box-sizing:border-box` for all elements.
- Add `aria-label` to search input instead of visually-hiding labels for accessibility
- Some style fixes
@JulienPalard

JulienPalard commented Jun 20, 2020

Copy link