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

Updates Image Editor slider to update rotation without requiring dragging, hides graduation list from AT #16218

Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Improved the accessibility of Checkboxes and Radio Buttons fields that allow custom options. ([#16080](https://github.com/craftcms/cms/pull/16080))
- Improved the accessibility of control panel icons. ([#16128](https://github.com/craftcms/cms/pull/16128))
- Improved the accessibility of Selectize inputs. ([#16110](https://github.com/craftcms/cms/pull/16110))
- Improved the accessibility of the image rotation control within the Image Editor. ([#16218](https://github.com/craftcms/cms/pull/16218))

### Administration
- Added the “Show the ‘URL Suffix’ field” setting to Link fields. ([#15813](https://github.com/craftcms/cms/discussions/15813))
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.

24 changes: 21 additions & 3 deletions src/web/assets/cp/src/css/_image_editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -427,21 +427,38 @@ html.noscroll body {
.slide-rule .graduations ul {
position: relative;
float: inline-start;
height: 40px;

/* We need to use "left" vs. a logical property here because that's wha the JS sets */
transition: 200ms left linear; /* stylelint-disable-line */
}

.slide-rule.dragging .graduations ul {
transition: none;
}

.slide-rule .graduations ul li {
display: inline-block;
font-size: 8px;
position: relative;
width: 10px;

&:hover {
cursor: pointer;

&::before {
border-inline-start-color: #63a6e1;
}
}
}

.slide-rule .graduations ul li:not(.main-graduation) {
inset-inline-start: 1px;
}

.slide-rule .graduations ul li.main-graduation::before {
border-inline-start-width: 3px;
border-inline-start-width: 4px;
height: 10px;
}

.slide-rule .graduations ul li.main-graduation .label {
Expand All @@ -456,8 +473,8 @@ html.noscroll body {
.slide-rule .graduations ul li::before {
content: '';
position: absolute;
border-inline-start: 1px solid var(--white);
height: 10px;
border-inline-start: 2px solid var(--white);
height: 6px;
inset-block-start: 0;
inset-inline-start: 0;
}
Expand Down Expand Up @@ -489,6 +506,7 @@ html.noscroll body {
position: absolute;
inset-block: 0 1px;
inset-inline: 0;
pointer-events: none;
background-image: linear-gradient(
to right,
var(--gray-900) 0%,
Expand Down
57 changes: 46 additions & 11 deletions src/web/assets/cp/src/js/SlideRuleInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Craft.SlideRuleInput = Garnish.Base.extend({
$selectedOption: null,
$input: null,
value: null,
dragging: false,
sensitivity: 3,
rotateIntent: false,

startPositionX: null,

Expand All @@ -24,7 +27,11 @@ Craft.SlideRuleInput = Garnish.Base.extend({
this.$graduations = $('<div class="graduations"></div>').appendTo(
this.$container
);
this.$graduationsUl = $('<ul></ul>').appendTo(this.$graduations);
this.$graduationsUl = $('<ul></ul>')
.attr({
'aria-hidden': 'true',
})
.appendTo(this.$graduations);

this.$container.attr({
role: 'slider',
Expand Down Expand Up @@ -126,25 +133,44 @@ Craft.SlideRuleInput = Garnish.Base.extend({
_handleTapStart: function (ev, touch) {
ev.preventDefault();

// Only allow rotation if the user taps on anything within the graduations container
this.rotateIntent = $(ev.target).is('.graduations *');

if (!this.rotateIntent) return;

this.startPositionX = touch.position.x;
this.startLeft = this.$graduationsUl.position().left;

this.dragging = true;
this.onStart();
},

_handleTapMove: function (ev, touch) {
if (this.dragging) {
ev.preventDefault();
if (!this.rotateIntent) return;

var curX = this.startPositionX - touch.position.x;
var left = this.startLeft - curX;
var value = this.positionToValue(left);
if (Math.abs(touch.position.x - this.startPositionX) > this.sensitivity) {
this.dragging = true;
this.$container.addClass('dragging');
ev.preventDefault();
this._setValueFromTouch(touch);
this.onChange();
}
},

this.setValue(value);
_setValueFromTouch: function (touch) {
let referencePosition = this.dragging
? this.startPositionX
: this.$cursor.offset().left + this.$cursor.outerWidth() / 2;
let delta;

this.onChange();
if (this.dragging) {
delta = referencePosition - touch.position.x;
} else {
delta = touch.position.x - referencePosition;
}

const position = this.startLeft - delta;
const value = this.positionToValue(position);
this.setValue(value);
},

setValue: function (value) {
Expand Down Expand Up @@ -191,12 +217,21 @@ Craft.SlideRuleInput = Garnish.Base.extend({
this.value = value;
},

_handleTapEnd: function (ev) {
_handleTapEnd: function (ev, touch) {
if (!this.rotateIntent) return;

if (this.dragging) {
ev.preventDefault();
this.dragging = false;
this.onEnd();
this.$container.removeClass('dragging');
} else {
this._setValueFromTouch(touch);
this.onChange();
}

this.onEnd();
this.startPositionX = null;
this.rotateIntent = false;
},

positionToValue: function (position) {
Expand Down