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

Accessibility Issue in Arranging the Menu Items #6238

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d86ec21
Select Field Addition
Rcreators Mar 6, 2024
9328675
Added $all_elements to all walker
Rcreators Mar 6, 2024
1d8a90f
Solved Unpack error for start_el
Rcreators Mar 6, 2024
92e340d
Parent update code complete
Rcreators Mar 6, 2024
a2e2679
PHP code update removed for parent dropdown
Rcreators Mar 8, 2024
317abaa
Revert few spaces issue in php code
Rcreators Mar 8, 2024
38994a6
Update select dropdown value with Js code
Rcreators Mar 8, 2024
bcf8d03
Updated some ordering issue
Rcreators Mar 8, 2024
f4dbb6b
Js minor update, PHP order change to select field
Rcreators Mar 8, 2024
51b3e06
Menu Order Dropdown updating on load and some code formatting
Rcreators Mar 8, 2024
e2af011
Remove menu item update menu order dropdown
Rcreators Mar 8, 2024
b1c00c4
Menu Order Change code added
Rcreators Mar 8, 2024
84b9e69
Some errors code updated
Rcreators Mar 8, 2024
825fedb
PHP white space issue
Rcreators Mar 9, 2024
dc3ded0
Js errors
Rcreators Mar 9, 2024
231f192
minor js error
Rcreators Mar 9, 2024
e0c2bc3
Most functionality done
Rcreators Mar 9, 2024
6497a77
Updated code for keyboard event
Rcreators Mar 11, 2024
0316b7e
Js code standard
Rcreators Mar 11, 2024
e52f7c9
Minor spacing issue
Rcreators Mar 16, 2024
fa4f6dc
Full Code done for Admin Menu Area
Rcreators Mar 16, 2024
ea984af
Js coding standards error solved
Rcreators Mar 16, 2024
d1c0db7
Adding selection dropdown to customizer template
Rcreators Mar 18, 2024
5e0905a
Refresh Code
Rcreators Mar 25, 2024
735013f
Customiser Code removed
Rcreators May 7, 2024
b98d661
Merge remote-tracking branch 'upstream/trunk' into pr/6238
joedolson Oct 8, 2024
f51c146
Walker Html Changes updated
Rcreators Oct 15, 2024
5e6d31f
Variable name fix
Rcreators Oct 15, 2024
750fac1
Speak Function Added.
Rcreators Oct 15, 2024
5004282
Final Nav Menu Js update
Rcreators Oct 15, 2024
96b9548
Fixed Minor parent changing issue not updating values
Rcreators Oct 15, 2024
0e3fdf9
Final Update for Parent Update Change
Rcreators Oct 16, 2024
85c88f0
Javascript Standard Update
Rcreators Oct 16, 2024
5cb2d99
Added Speak Translation
Rcreators Oct 16, 2024
77f808b
PHP Code Standard
Rcreators Oct 16, 2024
fa4bf0f
Move fields above mover buttons & update CSS to modernize & fix align…
joedolson Oct 20, 2024
e2c538d
Improve spacing per JS standards & remove deprecated .focus()
joedolson Oct 20, 2024
d24f81c
Comments, @since and var camelCase
joedolson Oct 20, 2024
65b376f
Setting newItemPosition to +1 moves items to be children of the next …
joedolson Oct 20, 2024
e50fb36
Update logic for Changing Order
Rcreators Oct 21, 2024
03c4e02
Minor Js issue.
Rcreators Oct 21, 2024
288c11f
Removed unused variable
Rcreators Oct 21, 2024
40de312
Remove unused variable
joedolson Oct 21, 2024
e968ba6
Merge branch '#43305' of https://github.com/Rcreators/wordpress-devel…
joedolson Oct 21, 2024
ebd2af7
Again missing semicolon
Rcreators Oct 21, 2024
e108874
Merge branch '#43305' of https://github.com/Rcreators/wordpress-devel…
Rcreators Oct 21, 2024
e9a294e
Merge branch 'WordPress:trunk' into #43305
Rcreators Oct 21, 2024
4872909
Expand spacing
joedolson Oct 21, 2024
123e75a
Ensure flex items expand to full width.
joedolson Oct 21, 2024
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
227 changes: 226 additions & 1 deletion src/js/_enqueues/lib/nav-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
checkboxes.prop( 'checked', false );
t.find( '.button-controls .select-all' ).prop( 'checked', false );
t.find( '.button-controls .spinner' ).removeClass( 'is-active' );
t.updateParentDropdown();
t.updateOrderDropdown();
});
});
},
Expand Down Expand Up @@ -288,6 +290,105 @@
});
});
return this;
},
updateParentDropdown : function() {
return this.each(function(){
var menuItems = $( '#menu-to-edit li' ),
parentDropdowns = $( '.edit-menu-item-parent' );

$.each( parentDropdowns, function() {
var parentDropdown = $( this ),
$html = '',
$selected = '',
currentItemID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-db-id' ).val(),
currentparentID = parentDropdown.closest( 'li.menu-item' ).find( '.menu-item-data-parent-id' ).val(),
currentItem = parentDropdown.closest( 'li.menu-item' ),
currentMenuItemChild = currentItem.childMenuItems(),
excludeMenuItem = [ currentItemID ];

if ( currentMenuItemChild.length > 0 ) {
$.each( currentMenuItemChild, function(){
var childItem = $(this),
childID = childItem.find( '.menu-item-data-db-id' ).val();

excludeMenuItem.push( childID );
});
}

if ( currentparentID == 0 ) {
$selected = 'selected';
}

$html += '<option ' + $selected + ' value="0">No Parent</option>';

$.each( menuItems, function() {
var menuItem = $(this),
$selected = '',
menuID = menuItem.find( '.menu-item-data-db-id' ).val(),
menuTitle = menuItem.find( '.edit-menu-item-title' ).val();

if ( ! excludeMenuItem.includes( menuID ) ) {
if ( currentparentID == menuID ) {
$selected = 'selected';
}
$html += '<option ' + $selected + ' value="' + menuID + '">' + menuTitle + '</option>';
}
});

parentDropdown.html( $html );
Rcreators marked this conversation as resolved.
Show resolved Hide resolved
});

});
},
updateOrderDropdown : function() {
return this.each( function() {
var itemPosition,
orderDropdowns = $( '.edit-menu-item-order' );

$.each( orderDropdowns, function() {
var orderDropdown = $( this ),
menuItem = orderDropdown.closest( 'li.menu-item' ).first(),
depth = menuItem.menuItemDepth(),
isPrimaryMenuItem = ( 0 === depth ),
$html = '',
$selected = '';

if ( isPrimaryMenuItem ) {
var primaryItems = $( '.menu-item-depth-0' ),
totalMenuItems = primaryItems.length;

itemPosition = primaryItems.index( menuItem ) + 1;

for ( let i = 1; i < totalMenuItems + 1; i++ ) {
$selected = '';
if ( i == itemPosition ) {
$selected = 'selected';
}
$html += '<option ' + $selected + ' value="' + i + '">' + i + ' of ' + totalMenuItems + '</option>';
}

} else {
var parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
totalSubMenuItems = subItems.length;

itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;

for ( let i = 1; i < totalSubMenuItems + 1; i++ ) {
$selected = '';
if ( i == itemPosition ) {
$selected = 'selected';
}
$html += '<option ' + $selected + ' value="' + i + '">' + i + ' of ' + totalSubMenuItems + '</option>';
}

}

orderDropdown.html( $html );
});

});
}
});
},
Expand All @@ -297,7 +398,6 @@
},

moveMenuItem : function( $this, dir ) {

var items, newItemPosition, newDepth,
menuItems = $( '#menu-to-edit li' ),
menuItemsCount = menuItems.length,
Expand Down Expand Up @@ -400,6 +500,8 @@
api.registerChange();
api.refreshKeyboardAccessibility();
api.refreshAdvancedAccessibility();
thisItem.updateParentDropdown();
thisItem.updateOrderDropdown();

if ( a11ySpeech ) {
wp.a11y.speak( a11ySpeech );
Expand Down Expand Up @@ -431,6 +533,123 @@
api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), dir );
}
});

// Set menu parents data for all menu items.
menu.updateParentDropdown();

// Set menu order data for all menu items.
menu.updateOrderDropdown();

// Update menu item parent when value is changed.
menu.on( 'change', '.edit-menu-item-parent', function() {
api.changeMenuParent( $( this ) );
});

// Update menu item order when value is changed.
menu.on( 'change', '.edit-menu-item-order', function() {
api.changeMenuOrder( $( this ) );
});
},

/**
* changeMenuParent( [parentDropdown] )
*
* @since 6.7.0
*
* @param {object} parentDropdown select field
*/
changeMenuParent : function( parentDropdown ) {
var menuItemNewPosition,
menuItems = $( '#menu-to-edit li' ),
$this = $( parentDropdown ),
newParentID = $this.val(),
menuItem = $this.closest( 'li.menu-item' ).first(),
menuItemOldDepth = menuItem.menuItemDepth(),
menuItemChildren = menuItem.childMenuItems(),
menuItemNoChildren = parseInt( menuItem.childMenuItems().length, 10 ),
parentItem = $( '#menu-item-' + newParentID ),
parentItemDepth = parentItem.menuItemDepth(),
menuItemNewDepth = parseInt( parentItemDepth ) + 1;

if ( newParentID == 0 ) {
menuItemNewDepth = 0;
}

menuItem.find( '.menu-item-data-parent-id' ).val( newParentID );
menuItem.moveHorizontally( menuItemNewDepth, menuItemOldDepth );

if ( menuItemNoChildren > 0 ) {
menuItem = menuItem.add( menuItemChildren );
}
menuItem.detach();

menuItems = $( '#menu-to-edit li' );

var parentItemPosition = parseInt( parentItem.index(), 10 ),
parentItemNoChild = parseInt( parentItem.childMenuItems().length, 10 );

if ( parentItemNoChild > 0 ){
menuItemNewPosition = parentItemPosition + parentItemNoChild;
} else {
menuItemNewPosition = parentItemPosition;
}

if ( newParentID == 0 ) {
menuItemNewPosition = menuItems.length - 1;
}

menuItem.insertAfter( menuItems.eq( menuItemNewPosition ) ).updateParentMenuItemDBId().updateParentDropdown().updateOrderDropdown();

api.registerChange();
api.refreshKeyboardAccessibility();
api.refreshAdvancedAccessibility();
$this.trigger( 'focus' );
wp.a11y.speak( menus.parentUpdated, 'polite' );
},

/**
* changeMenuOrder( [OrderDropdown] )
*
* @since 6.7.0
*
* @param {object} orderDropdown select field
*/
changeMenuOrder : function( orderDropdown ) {
var menuItems = $( '#menu-to-edit li' ),
$this = $( orderDropdown ),
newOrderID = parseInt( $this.val(), 10),
menuItem = $this.closest( 'li.menu-item' ).first(),
menuItemChildren = menuItem.childMenuItems(),
menuItemNoChildren = menuItemChildren.length,
menuItemCurrentPosition = parseInt( menuItem.index(), 10 ),
parentItemID = menuItem.find( '.menu-item-data-parent-id' ).val(),
subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemID + '"]' ),
currentItemAtPosition = $(subItems[newOrderID - 1]).closest( 'li.menu-item' );

if ( menuItemNoChildren > 0 ) {
menuItem = menuItem.add( menuItemChildren );
}

var currentItemNoChildren = currentItemAtPosition.childMenuItems().length,
currentItemPosition = parseInt( currentItemAtPosition.index(), 10 );

menuItems = $( '#menu-to-edit li' );

var menuItemNewPosition = currentItemPosition;

if(menuItemCurrentPosition > menuItemNewPosition){
menuItemNewPosition = currentItemPosition;
menuItem.detach().insertBefore( menuItems.eq( menuItemNewPosition ) ).updateOrderDropdown();
} else {
menuItemNewPosition = menuItemNewPosition + currentItemNoChildren;
menuItem.detach().insertAfter( menuItems.eq( menuItemNewPosition ) ).updateOrderDropdown();
}

api.registerChange();
api.refreshKeyboardAccessibility();
api.refreshAdvancedAccessibility();
$this.trigger( 'focus' );
wp.a11y.speak( menus.orderUpdated, 'polite' );
},

/**
Expand Down Expand Up @@ -737,6 +956,8 @@

api.refreshKeyboardAccessibility();
api.refreshAdvancedAccessibility();
ui.item.updateParentDropdown();
ui.item.updateOrderDropdown();
api.refreshAdvancedAccessibilityOfItem( ui.item.find( 'a.item-edit' ) );
},
change: function(e, ui) {
Expand Down Expand Up @@ -988,6 +1209,8 @@
deletionSpeech = menus.itemsDeleted.replace( '%s', itemsPendingDeletion );
wp.a11y.speak( deletionSpeech, 'polite' );
that.disableBulkSelection();
menus.updateParentDropdown();
menus.updateOrderDropdown();
}
});
},
Expand Down Expand Up @@ -1527,6 +1750,8 @@
}
api.refreshAdvancedAccessibility();
wp.a11y.speak( menus.itemRemoved );
menus.updateParentDropdown();
menus.updateOrderDropdown();
});
},

Expand Down
27 changes: 8 additions & 19 deletions src/wp-admin/css/nav-menus.css
Original file line number Diff line number Diff line change
Expand Up @@ -827,22 +827,13 @@ body.menu-max-depth-11 { min-width: 1280px !important; }
display: none;
}

.menu-item-settings .description-thin,
.menu-item-settings .description-wide {
margin-right: 10px;
float: left;
}

.description-thin {
width: calc(50% - 5px);
}

.menu-item-settings .description-thin + .description-thin {
margin-right: 0;
.description-group {
display: flex;
column-gap: 10px;
}

.description-wide {
width: 100%;
.description-group > * {
flex-grow: 1;
}

.menu-item-actions {
Expand Down Expand Up @@ -951,18 +942,16 @@ body.menu-max-depth-11 { min-width: 1280px !important; }
}

.menu-item-bar .menu-item-handle,
.menu-item-settings,
.description-wide {
.menu-item-settings {
width: auto;
}

.menu-item-settings {
padding: 10px;
}

.menu-item-settings .description-thin,
.menu-item-settings .description-wide {
width: 100%;
.menu-item-settings .description-group {
display: block;
}

.menu-item-settings input {
Expand Down
Loading
Loading