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

Improve accessibility of sidebar toggle on mobile element index pages, darken sidebar headings #11169

Merged
merged 17 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,17 @@ $radioSize: 16px;
box-shadow: var(--focus-ring);
}

@mixin visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}

@mixin readable {
font-size: 16px;
line-height: 22px;
Expand Down
7 changes: 6 additions & 1 deletion src/templates/_layouts/cp.twig
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@
{# sidebar #}
{% if sidebar %}
<div id="sidebar-toggle-container">
<button type="button" id="sidebar-toggle" class="btn menubtn"><span id="selected-sidebar-item-label"></span></button>
<button type="button" id="sidebar-toggle" class="btn menubtn" aria-controls="sidebar-container" aria-expanded="false">
{{ 'Show sidebar'|t('app') }}
</button>
</div>
<div id="sidebar-container">
<div id="sidebar" class="sidebar">
Expand All @@ -231,6 +233,9 @@

{# content-container #}
<div id="content-container">
{% if sidebar %}
<h2 id="content-heading"></h2>
{% endif %}
{% block main %}
<div id="content" class="content-pane">
{% if contentNotice or tabs %}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/cp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions src/web/assets/cp/src/css/_cp.scss
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,14 @@ li.breadcrumb-toggle-wrapper {
}
}

#content-heading {
margin-top: var(--xl) !important;

@media only screen and (min-width: $minHorizontalUiWidth) {
@include visually-hidden;
}
}

.content-pane {
@include pane;
border-radius: var(--large-border-radius);
Expand Down Expand Up @@ -1174,12 +1182,20 @@ li.breadcrumb-toggle-wrapper {
}

#sidebar-toggle {
&:after {
top: 0;
transform: rotate(-45deg);

body.rtl & {
transform: rotate(135deg);
}
}

body.showing-sidebar & {
background-color: darken($grey200, 10%) !important;

&:after {
transform: rotate(225deg);
top: 1px;
transform: rotate(45deg);
}
}
}
Expand Down Expand Up @@ -1302,7 +1318,7 @@ li.breadcrumb-toggle-wrapper {
padding: 0 5px;
margin: 0 -5px;
text-transform: uppercase;
color: var(--light-text-color);
color: var(--medium-text-color);
font-size: 11px;
font-weight: bold;
}
Expand Down
9 changes: 1 addition & 8 deletions src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -951,14 +951,7 @@ td.right {

// Visually hide without hiding from screen readers
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
@include visually-hidden;
}

.invisible {
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/src/js/BaseElementIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ Craft.BaseElementIndex = Garnish.Base.extend(
this.setInstanceState('selectedSource', this.sourceKey);
this.sourceSelect.selectItem($source);

Craft.cp.updateSidebarMenuLabel();
gcamacho079 marked this conversation as resolved.
Show resolved Hide resolved
Craft.cp.updateContentHeading();

if (this.searching) {
// Clear the search value without causing it to update elements
Expand Down
17 changes: 9 additions & 8 deletions src/web/assets/cp/src/js/CP.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Craft.CP = Garnish.Base.extend(

this.isMobile = Garnish.isMobileBrowser();

this.updateSidebarMenuLabel();
this.updateContentHeading();

// Swap any instruction text with info icons
let $allInstructions = this.$details.find(
Expand Down Expand Up @@ -456,12 +456,10 @@ Craft.CP = Garnish.Base.extend(
Craft.submitForm(this.$primaryForm, options);
},

updateSidebarMenuLabel: function () {
var $item = this.$sidebar.find('a.sel:first');
var $label = $item.children('.label');
$('#selected-sidebar-item-label').text(
$label.length ? $label.text() : $item.text()
);
updateContentHeading: function () {
const $item = this.$sidebar.find('a.sel:first');
const $label = $item.children('.label');
$('#content-heading').text($label.length ? $label.text() : $item.text());
Garnish.$bod.removeClass('showing-sidebar');
},

Expand Down Expand Up @@ -524,7 +522,10 @@ Craft.CP = Garnish.Base.extend(
);
},

toggleSidebar: function () {
toggleSidebar: function ({target}) {
Copy link
Member

Choose a reason for hiding this comment

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

If we need to accept a target here, it should just be a regular target argument, rather than an object. Then update the event handler to extract the target from the event data.

this.addListener($('#sidebar-toggle'), 'click', ({target}) => {
  this.toggleSidebar(target);
});

Also, the function should continue to work if target isn’t passed in, for backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the target variable, I thought I'd use a destructuring assignment to pull it out of the event object, to cut down on code inside the toggleSidebar function. I can re-work that though 👍🏼

Out of curiosity, what browsers/versions don't support target in this context? I'm not really versed on issues that would arise there. Appreciate the feedback!

Copy link
Member

Choose a reason for hiding this comment

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

Not a browser support issue; just an API clarity issue. toggleSidebar() should be something that can be called directly, without needing to pass an event object into.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I'll keep that in mind going forward

const expanded = target.getAttribute('aria-expanded') === 'true';
const newState = expanded ? 'false' : 'true';
target.setAttribute('aria-expanded', newState);
Garnish.$bod.toggleClass('showing-sidebar');
},

Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/dashboard/dist/css/Dashboard.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/edittransform/dist/css/transforms.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/edituser/dist/css/profile.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/generalsettings/dist/css/rebrand.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/graphiql/dist/css/graphiql.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/installer/dist/css/install.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/login/dist/css/login.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/money/dist/css/Money.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/plugins/dist/css/PluginManager.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/css/app.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/pluginstore/dist/js/app.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/routes/dist/css/routes.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/updater/dist/css/Updater.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/updates/dist/css/UpdatesUtility.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/upgrade/dist/css/UpgradeUtility.css.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/utilities/dist/css/utilities.css.map

Large diffs are not rendered by default.