Skip to content

Commit aba005b

Browse files
committed
Accessibility: Make sortable meta boxes non sortable when there are no locations they can be dragged to.
Depending on the amount of meta boxes and the layout settings under Screen Options, sortable meta boxes may not be actually sortable. In these cases, jQuery UI sortable needs to be disabled and the user interface shouldn't use a CSS `cursor: move`. The use of consistent and relevant cursors may be important for users who have a cognitive disability, since cursors give a visual clue as to an element's functionality. Using the move cursor for elements which cannot be moved may be confusing or counter-intuitive for users. Props adamsilverstein, antpb, anevins. Fixes #47131. git-svn-id: https://develop.svn.wordpress.org/trunk@46250 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 27a5302 commit aba005b

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

src/js/_enqueues/admin/common.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,8 @@ $document.ready( function() {
12741274
init: function() {
12751275
var self = this;
12761276

1277+
this.maybeDisableSortables = this.maybeDisableSortables.bind( this );
1278+
12771279
// Modify functionality based on custom activate/deactivate event
12781280
$document.on( 'wp-responsive-activate.wp-responsive', function() {
12791281
self.activate();
@@ -1313,13 +1315,31 @@ $document.ready( function() {
13131315
$document.on( 'wp-window-resized.wp-responsive', $.proxy( this.trigger, this ) );
13141316

13151317
// This needs to run later as UI Sortable may be initialized later on $(document).ready().
1316-
$window.on( 'load.wp-responsive', function() {
1317-
var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
1318+
$window.on( 'load.wp-responsive', this.maybeDisableSortables );
1319+
$document.on( 'postbox-toggled', this.maybeDisableSortables );
13181320

1319-
if ( width <= 782 ) {
1320-
self.disableSortables();
1321-
}
1322-
});
1321+
// When the screen columns are changed, potentially disable sortables.
1322+
$( '#screen-options-wrap input' ).on( 'click', this.maybeDisableSortables );
1323+
},
1324+
1325+
/**
1326+
* Disable sortables if there is only one metabox, or the screen is in one column mode. Otherwise, enable sortables.
1327+
*
1328+
* @since 5.3.0
1329+
*
1330+
* @returns {void}
1331+
*/
1332+
maybeDisableSortables: function() {
1333+
var width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? $window.width() : window.innerWidth;
1334+
1335+
if (
1336+
( width <= 782 ) ||
1337+
( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) )
1338+
) {
1339+
this.disableSortables();
1340+
} else {
1341+
this.enableSortables();
1342+
}
13231343
},
13241344

13251345
/**
@@ -1356,7 +1376,8 @@ $document.ready( function() {
13561376
deactivate: function() {
13571377
setPinMenu();
13581378
$adminmenu.removeData('wp-responsive');
1359-
this.enableSortables();
1379+
1380+
this.maybeDisableSortables();
13601381
},
13611382

13621383
/**
@@ -1391,6 +1412,8 @@ $document.ready( function() {
13911412
} else {
13921413
this.disableOverlay();
13931414
}
1415+
1416+
this.maybeDisableSortables();
13941417
},
13951418

13961419
/**
@@ -1439,6 +1462,7 @@ $document.ready( function() {
14391462
if ( $sortables.length ) {
14401463
try {
14411464
$sortables.sortable( 'disable' );
1465+
$sortables.find( '.ui-sortable-handle' ).addClass( 'is-non-sortable' );
14421466
} catch ( e ) {}
14431467
}
14441468
},
@@ -1454,6 +1478,7 @@ $document.ready( function() {
14541478
if ( $sortables.length ) {
14551479
try {
14561480
$sortables.sortable( 'enable' );
1481+
$sortables.find( '.ui-sortable-handle' ).removeClass( 'is-non-sortable' );
14571482
} catch ( e ) {}
14581483
}
14591484
}

src/wp-admin/css/common.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,11 @@ html.wp-toolbar {
20412041
cursor: move;
20422042
}
20432043

2044+
.js .widget .widget-top.is-non-sortable,
2045+
.js .postbox .hndle.is-non-sortable {
2046+
cursor: auto;
2047+
}
2048+
20442049
.hndle a {
20452050
font-size: 11px;
20462051
font-weight: 400;

0 commit comments

Comments
 (0)