mirror of
git://develop.git.wordpress.org/
synced 2025-03-24 05:49:49 +01:00
Menus: Validate custom links and add accessible error messages.
Some checks are pending
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions
Some checks are pending
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Waiting to run
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Blocked by required conditions
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Blocked by required conditions
Upgrade Develop Version Tests / Slack Notifications (push) Blocked by required conditions
Upgrade Develop Version Tests / Failed workflow tasks (push) Blocked by required conditions
Add URL validation in the admin navigation menu manager that matches the validation in the customizer when adding custom links. Improve accessibility of both custom link forms by adding `aria-invalid` and `aria-describedby` attributes with visible error messages and announcing the error using `wp.a11y.speak()`. Props joedolson, nikitasolanki1812, akrocks, pathan-amaankhan, rcreators, ironprogrammer, audrasjb, ankit-k-gupta, chaion07, rinkalpagdar, snehapatil02, jainil07, parthvataliya. Fixes #60619, #60969. git-svn-id: https://develop.svn.wordpress.org/trunk@59948 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
408a01ab8d
commit
c44c37d996
@ -1102,13 +1102,53 @@
|
||||
}, 500 ) );
|
||||
|
||||
$('#add-custom-links input[type="text"]').on( 'keypress', function(e){
|
||||
$('#customlinkdiv').removeClass('form-invalid');
|
||||
$( '#customlinkdiv' ).removeClass( 'form-invalid' );
|
||||
$( '#custom-menu-item-url' ).removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' );
|
||||
$( '#custom-url-error' ).hide();
|
||||
|
||||
if ( e.keyCode === 13 ) {
|
||||
e.preventDefault();
|
||||
$( '#submit-customlinkdiv' ).trigger( 'click' );
|
||||
}
|
||||
});
|
||||
|
||||
$( '#submit-customlinkdiv' ).on( 'click', function (e) {
|
||||
var urlInput = $( '#custom-menu-item-url' ),
|
||||
url = urlInput.val().trim(),
|
||||
errorMessage = $( '#custom-url-error' ),
|
||||
urlWrap = $( '#menu-item-url-wrap' ),
|
||||
urlRegex;
|
||||
|
||||
// Hide the error message initially
|
||||
errorMessage.hide();
|
||||
urlWrap.removeClass( 'has-error' );
|
||||
|
||||
/*
|
||||
* Allow URLs including:
|
||||
* - http://example.com/
|
||||
* - //example.com
|
||||
* - /directory/
|
||||
* - ?query-param
|
||||
* - #target
|
||||
* - mailto:foo@example.com
|
||||
*
|
||||
* Any further validation will be handled on the server when the setting is attempted to be saved,
|
||||
* so this pattern does not need to be complete.
|
||||
*/
|
||||
urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
|
||||
if ( ! urlRegex.test( url ) ) {
|
||||
e.preventDefault();
|
||||
urlInput.addClass( 'form-invalid' )
|
||||
.attr( 'aria-invalid', 'true' )
|
||||
.attr( 'aria-describedby', 'custom-url-error' );
|
||||
|
||||
errorMessage.show();
|
||||
var errorText = errorMessage.text();
|
||||
urlWrap.addClass( 'has-error' );
|
||||
// Announce error message via screen reader
|
||||
wp.a11y.speak( errorText, 'assertive' );
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
@ -1389,7 +1429,8 @@
|
||||
|
||||
addCustomLink : function( processMethod ) {
|
||||
var url = $('#custom-menu-item-url').val().toString(),
|
||||
label = $('#custom-menu-item-name').val();
|
||||
label = $('#custom-menu-item-name').val(),
|
||||
urlRegex;
|
||||
|
||||
if ( '' !== url ) {
|
||||
url = url.trim();
|
||||
@ -1397,7 +1438,20 @@
|
||||
|
||||
processMethod = processMethod || api.addMenuItemToBottom;
|
||||
|
||||
if ( '' === url || 'https://' == url || 'http://' == url ) {
|
||||
/*
|
||||
* Allow URLs including:
|
||||
* - http://example.com/
|
||||
* - //example.com
|
||||
* - /directory/
|
||||
* - ?query-param
|
||||
* - #target
|
||||
* - mailto:foo@example.com
|
||||
*
|
||||
* Any further validation will be handled on the server when the setting is attempted to be saved,
|
||||
* so this pattern does not need to be complete.
|
||||
*/
|
||||
urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
|
||||
if ( ! urlRegex.test( url ) ) {
|
||||
$('#customlinkdiv').addClass('form-invalid');
|
||||
return false;
|
||||
}
|
||||
|
@ -223,6 +223,9 @@
|
||||
|
||||
this.$el.on( 'input', '#custom-menu-item-name.invalid, #custom-menu-item-url.invalid', function() {
|
||||
$( this ).removeClass( 'invalid' );
|
||||
var errorMessageId = $( this ).attr( 'aria-describedby' );
|
||||
$( '#' + errorMessageId ).hide();
|
||||
$( this ).removeAttr( 'aria-invalid' ).removeAttr( 'aria-describedby' );
|
||||
});
|
||||
|
||||
// Load available items if it looks like we'll need them.
|
||||
@ -546,8 +549,11 @@
|
||||
var menuItem,
|
||||
itemName = $( '#custom-menu-item-name' ),
|
||||
itemUrl = $( '#custom-menu-item-url' ),
|
||||
urlErrorMessage = $( '#custom-url-error' ),
|
||||
nameErrorMessage = $( '#custom-name-error' ),
|
||||
url = itemUrl.val().trim(),
|
||||
urlRegex;
|
||||
urlRegex,
|
||||
errorText;
|
||||
|
||||
if ( ! this.currentMenuControl ) {
|
||||
return;
|
||||
@ -566,15 +572,37 @@
|
||||
* so this pattern does not need to be complete.
|
||||
*/
|
||||
urlRegex = /^((\w+:)?\/\/\w.*|\w+:(?!\/\/$)|\/|\?|#)/;
|
||||
|
||||
if ( '' === itemName.val() ) {
|
||||
itemName.addClass( 'invalid' );
|
||||
return;
|
||||
} else if ( ! urlRegex.test( url ) ) {
|
||||
itemUrl.addClass( 'invalid' );
|
||||
if ( ! urlRegex.test( url ) || '' === itemName.val() ) {
|
||||
if ( ! urlRegex.test( url ) ) {
|
||||
itemUrl.addClass( 'invalid' )
|
||||
.attr( 'aria-invalid', 'true' )
|
||||
.attr( 'aria-describedby', 'custom-url-error' );
|
||||
urlErrorMessage.show();
|
||||
errorText = urlErrorMessage.text();
|
||||
// Announce error message via screen reader
|
||||
wp.a11y.speak( errorText, 'assertive' );
|
||||
}
|
||||
if ( '' === itemName.val() ) {
|
||||
itemName.addClass( 'invalid' )
|
||||
.attr( 'aria-invalid', 'true' )
|
||||
.attr( 'aria-describedby', 'custom-name-error' );
|
||||
nameErrorMessage.show();
|
||||
errorText = ( '' === errorText ) ? nameErrorMessage.text() : errorText + nameErrorMessage.text();
|
||||
// Announce error message via screen reader
|
||||
wp.a11y.speak( errorText, 'assertive' );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
urlErrorMessage.hide();
|
||||
nameErrorMessage.hide();
|
||||
itemName.removeClass( 'invalid' )
|
||||
.removeAttr( 'aria-invalid', 'true' )
|
||||
.removeAttr( 'aria-describedby', 'custom-name-error' );
|
||||
itemUrl.removeClass( 'invalid' )
|
||||
.removeAttr( 'aria-invalid', 'true' )
|
||||
.removeAttr( 'aria-describedby', 'custom-name-error' );
|
||||
|
||||
menuItem = {
|
||||
'title': itemName.val(),
|
||||
'url': url,
|
||||
|
@ -377,11 +377,16 @@ input.bulk-select-switcher:focus + .bulk-select-button-label {
|
||||
|
||||
/* Add Menu Item Boxes */
|
||||
.postbox .howto input,
|
||||
.customlinkdiv .menu-item-textbox {
|
||||
.customlinkdiv .menu-item-textbox,
|
||||
.customlinkdiv .error-message {
|
||||
width: 180px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.customlinkdiv .error-message {
|
||||
clear: right;
|
||||
}
|
||||
|
||||
.accordion-container .outer-border {
|
||||
margin: 0;
|
||||
}
|
||||
|
@ -351,6 +351,7 @@ function wp_nav_menu_item_link_meta_box() {
|
||||
type="text"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?>
|
||||
class="code menu-item-textbox form-required" placeholder="https://"
|
||||
/>
|
||||
<span id="custom-url-error" class="error-message" style="display: none;"><?php _e( 'Please provide a valid link.' ); ?></span>
|
||||
</p>
|
||||
|
||||
<p id="menu-item-name-wrap" class="wp-clearfix">
|
||||
|
@ -1268,10 +1268,12 @@ final class WP_Customize_Nav_Menus {
|
||||
<p id="menu-item-url-wrap" class="wp-clearfix">
|
||||
<label class="howto" for="custom-menu-item-url"><?php _e( 'URL' ); ?></label>
|
||||
<input id="custom-menu-item-url" name="menu-item[-1][menu-item-url]" type="text" class="code menu-item-textbox" placeholder="https://">
|
||||
<span id="custom-url-error" class="error-message" style="display: none;"><?php _e( 'Please provide a valid link.' ); ?></span>
|
||||
</p>
|
||||
<p id="menu-item-name-wrap" class="wp-clearfix">
|
||||
<label class="howto" for="custom-menu-item-name"><?php _e( 'Link Text' ); ?></label>
|
||||
<input id="custom-menu-item-name" name="menu-item[-1][menu-item-title]" type="text" class="regular-text menu-item-textbox">
|
||||
<span id="custom-name-error" class="error-message" style="display: none;"><?php _e( 'The link text cannot be empty.' ); ?></span>
|
||||
</p>
|
||||
<p class="button-controls">
|
||||
<span class="add-to-menu">
|
||||
|
Loading…
x
Reference in New Issue
Block a user