Skip to content
Open
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
4 changes: 2 additions & 2 deletions classes/helpers/FrmListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ protected function pagination( $which ) {
$total_pages_before = '<span class="screen-reader-text">' . esc_html__( 'Current Page', 'formidable' ) . '</span><span id="table-paging" class="paging-input">';
} else {
$html_current_page = sprintf(
"%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
'<label for="current-page-selector" class="screen-reader-text">' . esc_html__( 'Current Page', 'formidable' ) . '</label>',
"<input class='current-page' id='current-page-selector' type='text' name='paged' aria-label='%s' value='%s' size='%d' aria-describedby='table-paging' />",
esc_attr__( 'Current Page', 'formidable' ),
$current,
strlen( $total_pages )
);
Expand Down
11 changes: 6 additions & 5 deletions classes/models/fields/FrmFieldTextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public function show_on_form_builder( $name = '' ) {
$max = FrmField::get_option( $this->field, 'max' );

$html_atts = array(
'name' => $this->html_name( $name ),
'id' => $this->html_id(),
'rows' => $max,
'class' => 'dyn_default_value',
'placeholder' => FrmField::get_option( $this->field, 'placeholder' ),
'name' => $this->html_name( $name ),
'id' => $this->html_id(),
'rows' => $max,
'class' => 'dyn_default_value',
'placeholder' => FrmField::get_option( $this->field, 'placeholder' ),
'aria-labelledby' => 'field_label_' . $this->field_id,
);

$size_style = $this->get_builder_size_style();
Expand Down
11 changes: 6 additions & 5 deletions classes/models/fields/FrmFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,12 @@ protected function builder_text_field( $name = '' ) {
}

$input_atts = array(
'type' => 'text',
'name' => $this->html_name( $name ),
'id' => $this->html_id(),
'value' => $value,
'placeholder' => $placeholder,
'type' => 'text',
'name' => $this->html_name( $name ),
'id' => $this->html_id(),
'value' => $value,
'placeholder' => $placeholder,
'aria-labelledby' => 'field_label_' . $this->field_id,
);

if ( $read_only ) {
Expand Down
2 changes: 1 addition & 1 deletion js/formidable-settings-components.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/formidable-web-components.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js/formidable_builder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/formidable_dashboard.js

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions js/src/admin/formOutline.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ export function initFormOutline() {
const focusedFieldId = focusedButton?.dataset.fieldId;
const focusedClass = focusedButton?.className;
list.replaceChildren( fragment );
if ( focusedFieldId !== undefined ) {
list.querySelector( `button.${ focusedClass }[data-field-id="${ focusedFieldId }"]` )?.focus( { preventScroll: true } );
}
emptyMessage.classList.toggle( 'frm_hidden', ! showEmpty );
search.parentElement.classList.toggle( 'frm_hidden', ! hasFields && ! loading );
if ( focusedFieldId !== undefined ) {
const replacement = list.querySelector( `button.${ focusedClass }[data-field-id="${ focusedFieldId }"]` );
const fallback = hasFields || loading ? search : toggle;
( replacement || fallback ).focus( { preventScroll: true } );
}
if ( noResults ) {
/* translators: %s: The search text */
emptyTitle.textContent = sprintf( __( 'No results for “%s”', 'formidable' ), search.value.trim() );
Expand All @@ -181,6 +183,10 @@ export function initFormOutline() {
announce( __( 'Loading fields…', 'formidable' ) );
return;
}
if ( ! hasFields && ! loading && ! query ) {
announce( emptyTitle.textContent );
return;
}
if ( query === '' ) {
announce( sprintf( _n( '%d page', '%d pages', pages.length, 'formidable' ), pages.length ) );
return;
Expand Down Expand Up @@ -361,6 +367,9 @@ export function initFormOutline() {
}
const items = Array.from( list.querySelectorAll( 'button[data-field-id]' ) );
if ( items.length === 0 ) {
if ( event.key === 'Enter' && event.target === search ) {
event.preventDefault();
}
return;
}
const index = items.indexOf( document.activeElement );
Expand Down
33 changes: 20 additions & 13 deletions js/src/components/tabs/class-tabs-navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class frmTabsNavigator {
this.resizeObserver = null;
this.filterTarget = getFilterTarget( this.wrapper );

this.controls = Array.from( this.navs, nav => nav.querySelector( ':scope > a:only-child' ) || nav );

this.init();
}

Expand Down Expand Up @@ -55,18 +57,23 @@ export class frmTabsNavigator {
this.navs.forEach( ( nav, index ) => {
const isSelected = index === selectedIndex;
nav.classList.toggle( 'frm-active', isSelected );
nav.setAttribute( 'tabindex', this.filterTarget || isSelected ? '0' : '-1' );
nav.setAttribute( 'role', this.filterTarget ? 'button' : 'tab' );
nav.setAttribute( this.filterTarget ? 'aria-pressed' : 'aria-selected', String( isSelected ) );
nav.querySelectorAll( 'a' ).forEach( anchor => anchor.setAttribute( 'tabindex', '-1' ) );
const control = this.controls[ index ];
if ( control !== nav ) {
nav.setAttribute( 'role', 'presentation' );
} else {
nav.querySelectorAll( 'a' ).forEach( anchor => anchor.setAttribute( 'tabindex', '-1' ) );
}
control.setAttribute( 'tabindex', this.filterTarget || isSelected ? '0' : '-1' );
control.setAttribute( 'role', this.filterTarget ? 'button' : 'tab' );
control.setAttribute( this.filterTarget ? 'aria-pressed' : 'aria-selected', String( isSelected ) );

if ( ! this.filterTarget && this.slides[ index ] ) {
const panel = this.slides[ index ];
nav.id = nav.id || `${ idPrefix }-tab-${ index }`;
control.id = control.id || `${ idPrefix }-tab-${ index }`;
panel.id = panel.id || `${ idPrefix }-panel-${ index }`;
nav.setAttribute( 'aria-controls', panel.id );
control.setAttribute( 'aria-controls', panel.id );
panel.setAttribute( 'role', 'tabpanel' );
panel.setAttribute( 'aria-labelledby', nav.id );
panel.setAttribute( 'aria-labelledby', control.id );
panel.setAttribute( 'tabindex', '0' );
}

Expand Down Expand Up @@ -98,10 +105,10 @@ export class frmTabsNavigator {

this.removeActiveClassnameFromNavs();
navItem.classList.add( 'frm-active' );
this.navs.forEach( nav => {
nav.setAttribute( this.filterTarget ? 'aria-pressed' : 'aria-selected', String( nav === navItem ) );
this.controls.forEach( ( control, navIndex ) => {
control.setAttribute( this.filterTarget ? 'aria-pressed' : 'aria-selected', String( navIndex === index ) );
if ( ! this.filterTarget ) {
nav.setAttribute( 'tabindex', nav === navItem ? '0' : '-1' );
control.setAttribute( 'tabindex', navIndex === index ? '0' : '-1' );
}
} );
this.initSlideTrackUnderline( navItem );
Expand All @@ -112,7 +119,7 @@ export class frmTabsNavigator {
}

this.changeSlide( index );
this.keepFocusOnTab( navItem );
this.keepFocusOnTab( this.controls[ index ] );

// Handle special case for frm_insert_fields_tab
const navLink = navItem.querySelector( 'a' );
Expand Down Expand Up @@ -151,8 +158,8 @@ export class frmTabsNavigator {
}

event.preventDefault();
this.navs.forEach( ( nav, navIndex ) => nav.setAttribute( 'tabindex', navIndex === nextIndex ? '0' : '-1' ) );
this.navs[ nextIndex ].focus();
this.controls.forEach( ( nav, navIndex ) => nav.setAttribute( 'tabindex', navIndex === nextIndex ? '0' : '-1' ) );
this.controls[ nextIndex ].focus();
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/cypress/e2e/Forms/formOutline.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ describe( 'Form outline', { retries: 0 }, () => {
} );
};

it( 'keeps keyboard focus in the outline when a matching field disappears', () => {
addField( 'text' );
addField( 'email' );
cy.get( '#frm_insert_fields_tab' ).focus().type( '{end}' );
cy.focused().should( 'have.id', 'frm-builder-outline-toggle' ).type( '{enter}' );
cy.get( '#frm-builder-outline-toggle' ).should( 'have.attr', 'aria-selected', 'true' );
search( 'Text' );
cy.get( '.frm-builder-outline-status' ).should( 'have.text', '1 matching result found.' );
cy.injectAxe();
cy.checkA11y( '.frm-settings-panel [role="tablist"]' );
cy.checkA11y( '#frm-show-fields .frm_opt_container input[type="text"]' );
cy.checkA11y( '#frm-builder-outline' );
cy.get( '.frm-builder-outline-field' ).first().focus().then( button => {
const fieldId = button.attr( 'data-field-id' );
cy.get( `#frm-show-fields li[data-fid="${ fieldId }"]` ).then( field => field.remove() );
} );
cy.get( '#frm-builder-outline-search-input' ).should( 'have.focus' );
cy.get( '.frm-builder-outline-status' ).should( 'have.text', 'No pages or fields found.' );
cy.focused().then( input => {
const event = new KeyboardEvent( 'keydown', { key: 'Enter', bubbles: true, cancelable: true } );
expect( input[ 0 ].dispatchEvent( event ) ).to.equal( false );
} );
cy.checkA11y( '#frm-builder-outline' );
} );

it( 'keeps a field reachable after clearing its label in Field Options', () => {
addField( 'text' );
addPageBreak();
Expand Down
5 changes: 1 addition & 4 deletions tests/cypress/e2e/admin-a11y.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ describe( 'Run some accessibility tests', function() {
it( 'Check the form list is accessible', () => {
cy.visit( '/wp-admin/admin.php?page=formidable' );
cy.injectAxe();
configureAxeWithIgnoredRuleset( [
...baselineRules,
{ id: 'empty-table-header', enabled: false }
] );
configureAxeWithIgnoredRuleset( baselineRules );
cy.checkA11y( excludeAdminBar, null, violations => {
const summary = logViolations( violations );
expect( violations, summary ).to.have.lengthOf( 0 );
Expand Down
4 changes: 0 additions & 4 deletions tests/cypress/fixtures/ibm-a11y-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
}
},
"formidable-form-list": {
"label_content_exists": {
"reason": "Form-row checkbox labels have no descriptive text. The number depends on the forms in the list.",
"observedViolations": 1
},
"label_name_visible": {
"reason": "The WordPress sidebar collapse button accessible name does not contain its visible label.",
"maxViolations": 1
Expand Down