Skip to content

Commit

Permalink
Course outline block enhance (#2776)
Browse files Browse the repository at this point in the history
* Make headers collapse/open when clicked anywhere.

* Fix a11y.

* Fix focus ring on lesson item gets hidden.

* Fix the button focus ring size too small on Firefox.

* Remove module heading link.

* Remove the link within the button span with class "screen-reader-text" if it exists
  • Loading branch information
renintw authored Jul 31, 2024
1 parent 5bec934 commit 50d69fc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
34 changes: 34 additions & 0 deletions wp-content/themes/pub/wporg-learn-2024/src/course-outline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,40 @@ import { Icon, drafts, lockOutline } from '@wordpress/icons';
import { renderToString } from '@wordpress/element';

document.addEventListener( 'DOMContentLoaded', () => {
/**
* Allow the entire header to toggle, giving users a larger area to interact with.
*/
document
.querySelectorAll( 'section.wp-block-sensei-lms-course-outline-module-bordered > header' )
.forEach( ( header ) => {
const button = header.querySelector( 'button' );
header.addEventListener( 'click', () => {
button.click();
} );

button.addEventListener( 'click', ( event ) => {
event.stopPropagation();
} );

// To enable the entire header to be clickable for toggling without conflicts, remove the link.
// In fact, this link duplicates the first lesson link in the course outline.
// See https://github.com/WordPress/Learn/pull/2776#issuecomment-2258308422
const link = header.querySelector( 'h2 > a' );
if ( link ) {
const heading = link.parentElement;
heading.innerHTML = link.innerHTML;
}
// Also remove the link within the span with class "screen-reader-text" if it exists.
const span = header.querySelector( 'span.screen-reader-text' );
if ( span ) {
const spanLink = span.querySelector( 'a' );
if ( spanLink ) {
const spanContent = spanLink.innerHTML;
span.innerHTML = spanContent;
}
}
} );

/**
* Find all in progress lessons, and replace the status icon with the Gutenberg-style `drafts` icon.
*/
Expand Down
21 changes: 15 additions & 6 deletions wp-content/themes/pub/wporg-learn-2024/src/style/_sensei.scss
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ body.sensei {
header {
background-color: var(--wp--preset--color--light-grey-2) !important;
color: var(--wp--preset--color--charcoal-1) !important;
padding: var(--wp--preset--spacing--20);
padding-left: var(--wp--preset--spacing--20);
padding-right: var(--wp--preset--spacing--20);
cursor: pointer;

h2 {
font-size: var(--wp--preset--font-size--heading-6);
Expand All @@ -160,19 +162,26 @@ body.sensei {
margin: 4px 8px;
}
}
}

.wp-block-sensei-lms-course-outline-module__lessons-title {
display: none;
button.wp-block-sensei-lms-course-outline__arrow {
height: 32px;
align-items: center;
}
}

.wp-block-sensei-lms-collapsible {
overflow: unset;

h3.wp-block-sensei-lms-course-outline-module__lessons-title {
display: none;
}

// lesson item that belongs to a module
> .wp-block-sensei-lms-course-outline-lesson:first-of-type {
> a.wp-block-sensei-lms-course-outline-lesson:first-of-type {
padding-top: 5px;
}

> .wp-block-sensei-lms-course-outline-lesson:last-of-type {
> a.wp-block-sensei-lms-course-outline-lesson:last-of-type {
padding-bottom: 5px;
}
}
Expand Down

0 comments on commit 50d69fc

Please sign in to comment.