From f1f9fd8ab5cc96068adaefce944cf6183a26738b Mon Sep 17 00:00:00 2001 From: Erik Strid Date: Fri, 15 Nov 2024 07:39:41 +0100 Subject: [PATCH 1/3] Improved accessability and screen reader support --- .../html/autocomplete/wicket-autocomplete.js | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js index 6187d18e0a4..3c8fd753933 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js @@ -136,6 +136,7 @@ showAutoComplete(); } render(true, false); + jqEvent.preventDefault(); } break; @@ -153,6 +154,7 @@ render(true, false); showAutoComplete(); } + jqEvent.preventDefault(); } break; @@ -243,7 +245,7 @@ { // Remove the autocompletion menu if still present from // a previous call. This is required to properly register - // the mouse event handler again + // the mouse event handler again var choiceDiv=document.getElementById(getMenuId()); if (choiceDiv !== null) { choiceDiv.parentNode.parentNode.removeChild(choiceDiv.parentNode); @@ -325,7 +327,6 @@ container.appendChild(choiceDiv); choiceDiv.id=getMenuId(); choiceDiv.className = "wicket-aa"; - choiceDiv.ariaLive = "polite"; } @@ -404,6 +405,9 @@ var container = getAutocompleteContainer(); var index=getOffsetParentZIndex(ajaxAttributes.c); container.show(); + + input.setAttribute("aria-expanded", "true"); + if (!isNaN(Number(index))) { container.style.zIndex=(Number(index)+1); } @@ -441,6 +445,11 @@ function hideAutoComplete(){ hideAutoCompleteTimer = undefined; + + var input = Wicket.$(ajaxAttributes.c); + input.setAttribute("aria-expanded", "false"); + input.removeAttribute("aria-activedescendant"); + visible = 0; setSelected(-1); @@ -612,6 +621,7 @@ selChSinceLastRender = true; // selected item will not have selected style until rendrered } element.innerHTML=resp; + element.firstChild.role = "listbox" var selectableElements = getSelectableElements(); if (selectableElements) { elementCount=selectableElements.length; @@ -659,6 +669,11 @@ node.onclick = clickFunc; node.onmouseover = mouseOverFunc; node.onmousedown = mouseDownFunc; + node.role = "option"; + node.id = getMenuId() + '-item-' + i; + node.setAttribute("tabindex", -1); + node.setAttribute("aria-posinset", i + 1) + node.setAttribute("aria-setsize", elementCount) } } else { elementCount=0; @@ -754,16 +769,26 @@ var node=getSelectableElement(0); var re = /\bselected\b/gi; var sizeAffected = false; + var input=Wicket.$(ajaxAttributes.c); + for(var i=0;i Date: Fri, 15 Nov 2024 11:27:00 +0100 Subject: [PATCH 2/3] Ensure that the input field exists before trying to change its attributes --- .../ajax/markup/html/autocomplete/wicket-autocomplete.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js index 3c8fd753933..8a5bd5a53ee 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js @@ -447,8 +447,10 @@ hideAutoCompleteTimer = undefined; var input = Wicket.$(ajaxAttributes.c); - input.setAttribute("aria-expanded", "false"); - input.removeAttribute("aria-activedescendant"); + if (input) { + input.setAttribute("aria-expanded", "false"); + input.removeAttribute("aria-activedescendant"); + } visible = 0; setSelected(-1); From 3f5153f56a9d1368c6c849f068d57cdd48b7e45d Mon Sep 17 00:00:00 2001 From: Erik Strid Date: Tue, 19 Nov 2024 09:06:00 +0100 Subject: [PATCH 3/3] Fix code style issues --- .../ajax/markup/html/autocomplete/wicket-autocomplete.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js index 8a5bd5a53ee..262c35b1b76 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js @@ -469,7 +469,6 @@ if (triggerChangeOnHide) { triggerChangeOnHide = false; - var input = Wicket.$(ajaxAttributes.c); isTriggeredChange = true; jQuery(input).trigger('change'); } @@ -623,7 +622,7 @@ selChSinceLastRender = true; // selected item will not have selected style until rendrered } element.innerHTML=resp; - element.firstChild.role = "listbox" + element.firstChild.role = "listbox"; var selectableElements = getSelectableElements(); if (selectableElements) { elementCount=selectableElements.length; @@ -674,8 +673,8 @@ node.role = "option"; node.id = getMenuId() + '-item-' + i; node.setAttribute("tabindex", -1); - node.setAttribute("aria-posinset", i + 1) - node.setAttribute("aria-setsize", elementCount) + node.setAttribute("aria-posinset", i + 1); + node.setAttribute("aria-setsize", elementCount); } } else { elementCount=0;