Skip to content

Commit

Permalink
Merge pull request #12189 from craftcms/a11y/update-accordions
Browse files Browse the repository at this point in the history
A11y/update accordions
  • Loading branch information
brandonkelly authored Jan 5, 2023
2 parents b240a23 + c4c6442 commit 1945e8a
Show file tree
Hide file tree
Showing 18 changed files with 284 additions and 85 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Accessibility
- Improved the announcement menu for screen readers. ([#12361](https://github.com/craftcms/cms/pull/12361))
- Improved keyboard control for the Updates utility. ([#12189](https://github.com/craftcms/cms/pull/12189))

### Administration
- Conditional layout components are now identified using a condition icon within field layout designers. ([#12250](https://github.com/craftcms/cms/issues/12250))
Expand Down Expand Up @@ -49,6 +50,7 @@
- Added `craft\services\Users::EVENT_BEFORE_SAVE_USER_PHOTO`. ([#12360](https://github.com/craftcms/cms/pull/12360))
- Renamed `craft\elements\conditions\assets\EditableConditionRule` to `SavableConditionRule`, while preserving the original class name with an alias. ([#12266](https://github.com/craftcms/cms/pull/12266))
- Renamed `craft\elements\conditions\entries\EditableConditionRule` to `SavableConditionRule`, while preserving the original class name with an alias. ([#12266](https://github.com/craftcms/cms/pull/12266))
- Added `Craft.Accordion`. ([#12189](https://github.com/craftcms/cms/pull/12189))
- Added `Craft.ElementFieldSettings`.
- Deprecated `Craft.CategorySelectInput`. `Craft.BaseElementSelectInput` should be used instead. ([#11749](https://github.com/craftcms/cms/pull/11749))

Expand Down
26 changes: 19 additions & 7 deletions packages/craftcms-sass/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -703,42 +703,54 @@ $radioSize: 16px;
line-height: 22px;

h1,
.h1,
h2,
.h2,
h3,
.h3,
h4,
.h4,
h5,
h6 {
.h5,
h6,
.h6 {
margin: 24px 0 16px;
font-weight: 600;
}

h1 {
h1,
.h1 {
font-size: 32px;
line-height: 40px;
color: #000;
}

h2 {
h2,
.h2 {
font-size: 24px;
line-height: 30px;
}

h3 {
h3,
.h3 {
font-size: 20px;
line-height: 24px;
}

h4 {
h4,
.h4 {
font-size: 16px;
line-height: 20px;
}

h5 {
h5,
.h5 {
font-size: 14px;
line-height: 18px;
}

h6 {
h6,
.h6 {
font-size: 13.6px;
line-height: 17px;
color: $mediumTextColor;
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.

1 change: 1 addition & 0 deletions src/web/assets/cp/src/Craft.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import './js/ElementEditorSlideout.js';
import './js/Tabs.js';

// Finally load the remaining files
import './js/Accordion';
import './js/AddressesInput.js';
import './js/AdminTable.js';
import './js/AssetImageEditor.js';
Expand Down
130 changes: 130 additions & 0 deletions src/web/assets/cp/src/js/Accordion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/** global: Craft */
/** global: Garnish */
/**
* Accordion
*/
Craft.Accordion = Garnish.Base.extend({
$trigger: null,
targetSelector: null,

_$target: null,

init: function (trigger) {
this.$trigger = $(trigger);

// Is this already an accordion trigger?
if (this.$trigger.data('accordion')) {
console.warn('Double-instantiating an accordion trigger on an element');
this.$trigger.data('accordion').destroy();
}

this.$trigger.data('accordion', this);
this.targetSelector = this.$trigger.attr('aria-controls')
? `#${this.$trigger.attr('aria-controls')}`
: null;

if (this.targetSelector) {
this._$target = $(this.targetSelector);
}

this.addListener(this.$trigger, 'click', 'onTriggerClick');
this.addListener(this.$trigger, 'keypress', (event) => {
const key = event.keyCode;

if (key === Garnish.SPACE_KEY || key === Garnish.RETURN_KEY) {
event.preventDefault();
this.onTriggerClick();
}
});
},

onTriggerClick: function () {
const isOpen = this.$trigger.attr('aria-expanded') === 'true';

if (isOpen) {
this.hideTarget(this._$target);
} else {
this.showTarget(this._$target);
}
},

showTarget: function ($target) {
if ($target && $target.length) {
this.showTarget._currentHeight = $target.height();

$target.removeClass('hidden');

this.$trigger
.removeClass('collapsed')
.addClass('expanded')
.attr('aria-expanded', 'true');

for (let i = 0; i < $target.length; i++) {
(($t) => {
if ($t.prop('nodeName') !== 'SPAN') {
$t.height('auto');
this.showTarget._targetHeight = $t.height();
$t.css({
height: this.showTarget._currentHeight,
overflow: 'hidden',
});

$t.velocity('stop');

$t.velocity(
{height: this.showTarget._targetHeight},
Garnish.getUserPreferredAnimationDuration('fast'),
function () {
$t.css({
height: '',
overflow: '',
});
}
);
}
})($target.eq(i));
}

delete this.showTarget._targetHeight;
delete this.showTarget._currentHeight;

// Trigger a resize event in case there are any grids in the target that need to initialize
Garnish.$win.trigger('resize');
}
},

hideTarget: function ($target) {
if ($target && $target.length) {
this.$trigger
.removeClass('expanded')
.addClass('collapsed')
.attr('aria-expanded', 'false');

for (let i = 0; i < $target.length; i++) {
(($t) => {
if ($t.hasClass('hidden')) {
return;
}
if ($t.prop('nodeName') === 'SPAN') {
$t.addClass('hidden');
} else {
$t.css('overflow', 'hidden');
$t.velocity('stop');
$t.velocity(
{height: 0},
Garnish.getUserPreferredAnimationDuration('fast'),
function () {
$t.addClass('hidden');
}
);
}
})($target.eq(i));
}
}
},

destroy: function () {
this.$trigger.removeData('accordion');
this.base();
},
});
52 changes: 30 additions & 22 deletions src/web/assets/cp/src/js/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ Craft.Preview = Garnish.Base.extend(
'LivePreview.editorWidth',
Craft.Preview.defaultEditorWidth
);
this.setAnimationDuration();

Craft.Preview.instances.push(this);
},
Expand Down Expand Up @@ -119,16 +118,11 @@ Craft.Preview = Garnish.Base.extend(
this._editorWidthInPx = inPx;
},

setAnimationDuration: function () {
this.animationDuration = Garnish.prefersReducedMotion() ? 0 : 'slow';
},

open: function () {
if (this.isActive) {
return;
}

this.setAnimationDuration();
this.isActive = true;
this.trigger('beforeOpen');

Expand Down Expand Up @@ -462,15 +456,22 @@ Craft.Preview = Garnish.Base.extend(
this.$editorContainer
.show()
.velocity('stop')
.animateLeft(0, this.animationDuration, () => {
this.trigger('slideIn');
Garnish.$win.trigger('resize');
});
.animateLeft(
0,
Garnish.getUserPreferredAnimationDuration(this.animationDuration),
() => {
this.trigger('slideIn');
Garnish.$win.trigger('resize');
}
);

this.$previewContainer
.show()
.velocity('stop')
.animateRight(0, this.animationDuration);
.animateRight(
0,
Garnish.getUserPreferredAnimationDuration(this.animationDuration)
);

this.isVisible = true;

Expand All @@ -488,7 +489,6 @@ Craft.Preview = Garnish.Base.extend(
return;
}

this.setAnimationDuration();
this.trigger('beforeClose');

$('html').removeClass('noscroll');
Expand All @@ -510,20 +510,28 @@ Craft.Preview = Garnish.Base.extend(

this.$editorContainer
.velocity('stop')
.animateLeft(-this.editorWidthInPx, this.animationDuration, () => {
for (var i = 0; i < this.fields.length; i++) {
this.fields[i].$newClone.remove();
.animateLeft(
-this.editorWidthInPx,
Garnish.getUserPreferredAnimationDuration(this.animationDuration),
() => {
for (var i = 0; i < this.fields.length; i++) {
this.fields[i].$newClone.remove();
}
this.$editorContainer.hide();
this.trigger('slideOut');
}
this.$editorContainer.hide();
this.trigger('slideOut');
});
);

this.$previewContainer
.velocity('stop')
.animateRight(-this.getIframeWidth(), this.animationDuration, () => {
this.$iframeContainer.removeClass('lp-iframe-container--rotating');
this.$previewContainer.hide();
});
.animateRight(
-this.getIframeWidth(),
Garnish.getUserPreferredAnimationDuration(this.animationDuration),
() => {
this.$iframeContainer.removeClass('lp-iframe-container--rotating');
this.$previewContainer.hide();
}
);

this.elementEditor.off('update', this._updateIframeProxy);

Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/garnish/dist/garnish.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/web/assets/garnish/src/Garnish.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ Garnish = $.extend(Garnish, {
return !mediaQuery || mediaQuery.matches;
},

/**
* Returns either '0' or a set duration, based on a user's prefers-reduced-motion setting
* Used to set the duration inside the Velocity.js options object in a way that respects user preferences
* @param {string|integer} duration Either a ms duration or a named jQuery duration (i.e. 'fast', 'slow')
* @return {string|integer}
*/
getUserPreferredAnimationDuration: function (duration) {
return Garnish.prefersReducedMotion() ? 0 : duration;
},

/**
* Returns whether a variable is an array.
*
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/updates/dist/UpdatesUtility.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

Loading

0 comments on commit 1945e8a

Please sign in to comment.