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

Fix/lm sticky sidebar #6304

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
Open

Fix/lm sticky sidebar #6304

wants to merge 10 commits into from

Conversation

dadish
Copy link
Contributor

@dadish dadish commented Dec 15, 2022

Fixes #5912

Changes proposed in this Pull Request

  • Makes the sidebar for modern and full-video templates sticky.
  • For modern template if featured video is taller than the sidebar, then it makes the sidebar the same height.
  • If the sidebar is very tall and does not fit into the viewport vertically, then it scrolls up/down so users can reach all the sidebar content.
  • Updates sidebar position when the viewport is resized.

Testing instructions

  • Try out different scenarios. Like shown in the video below.
  • Make sure the sticky sidebar sticks when it makes sense.

Screenshot / Video

Regular Sticky Sidebar

sticky-sidebar-regular.mp4

Full Video Sticky Sidebar

sticky-sidebar-full-video.mp4

Height Overflow Sticky Sidebar

sticky-sidebar-height-overflow.mp4

Video Height Sticky Sidebar

sticky-sidebar-video-height.mp4

Video Full Height Overflow Sticky Sidebar

sticky-sidebar-full-video-height-overflow.mp4

@dadish dadish marked this pull request as ready for review December 15, 2022 15:07
@dadish dadish requested a review from a team December 15, 2022 15:08
@codecov
Copy link

codecov bot commented Dec 15, 2022

Codecov Report

Merging #6304 (d49d886) into trunk (086650c) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #6304      +/-   ##
============================================
- Coverage     45.97%   45.97%   -0.01%     
- Complexity     9551     9552       +1     
============================================
  Files           459      459              
  Lines         33837    33842       +5     
  Branches        275      275              
============================================
  Hits          15558    15558              
- Misses        18074    18079       +5     
  Partials        205      205              
Impacted Files Coverage Δ
...urse-theme/class-sensei-course-theme-templates.php 3.72% <0.00%> (-0.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d6a1dc...d49d886. Read the comment docs.

Copy link
Contributor

@yscik yscik left a comment

Choose a reason for hiding this comment

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

Looks beautiful 😍
Got some code suggestions:

Comment on lines 81 to 83
* Creates an exact copy of the sidebar DOM element
* and sets it's position to fixed. The original sidebar
* element is hidden by seting it's opacity to 0. The clone, "stickySidebar"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have add some placeholder element instead, to avoid having the sidebar duplicated? If not, let's try to make this accessible and ensure the hidden element is not causing issues. visibility: hidden instead of the opacity change will still keep the element it in the layout, but remove it from the accessibility tree. I think you also can't TAB into it, but not 100% sure. (And could also add aria-hidden to make it explicit.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I went with the placeholder element approach. Much better now. It also fixes the bug where you couldn't expand/collapse course modules in the sidebar. I realized it is not working just today. 😅

4cbd7b6

stickySidebar.remove();
}
stickySidebar = sidebar.cloneNode( true );
stickySidebar.style.position = 'fixed';
Copy link
Contributor

Choose a reason for hiding this comment

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

Would position: sticky be usable as a starting point? The browser would take away some of the positioning math and adjustments. Or is it harder to work with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah. I tried the position: sticky approach initially. I couldn't make it work properly.

Comment on lines 29 to 31
[ 'modern', 'video-full' ].some( ( templateName ) =>
document.body.classList.contains( `learning-mode--${ templateName }` )
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use something like an .is-sticky class on the sidebar block instead? Coding it to template names makes it hard to figure out where this behavior is coming from and why it's only happening in some cases.
With an .is-sticky class, we can also build it into a setting toggle in the editor later.

(This does mean changing the templates, which won't affect folks who customized it already, but that's probably for the best.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're probably right. It's better to have that info close to the sidebar blocks.

Although the block is not strictly a sidebar block. It's variation of the sensei-lms/ui block. I'm sure there is a way to add some sort of block setting depending on the block variation. I didn't spend time to figure that out though. Didn't want to turn this into bigger project.

What I did instead is I added a custom class name in the Advanced section of the Sidebar Menu block. So it's on by default and can be removed by the user if they want to. Maybe we can turn it into a block setting with a better UI. For now I think this approach is sufficient.

Checkout the change in the sensei pro repo here: https://github.com/Automattic/sensei-pro/pull/1988

b5c8462

assets/course-theme/sidebar.js Show resolved Hide resolved
@dadish dadish requested a review from yscik December 16, 2022 13:15
@gikaragia
Copy link
Contributor

Hey @yscik do you think this needs more work to get it merged?

@github-actions
Copy link

WordPress Dependencies Report

The github-action-wordpress-dependencies-report action has detected some script changes between the commit d49d886 and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Dependencies Removed Dependencies Total Size Size Diff
course-theme/learning-mode.js 8.26 kB +1.11 kB ( +15.61% 🔼 )

This comment was automatically generated by the github-action-wordpress-dependencies-report action.

@yscik
Copy link
Contributor

yscik commented Jan 18, 2023

Code looks good! Did some testing, logging a few issues here that we should look into:

When the content is shorter than the sidebar, the sidebar bottom is cut off and can't be accessed:

Sticky-sidebar-short-content.mov

Weird issue of a contact teacher thing appearing:

Sticky-contact-teacher.mov

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.

LM Modern - Make sidebar sticky
3 participants