Commit c8e01d3e authored by Sebastien Robin's avatar Sebastien Robin

erp5_web_renderjs_ui: enable keyboard to navigate relation field menu

some improvements:
- use xpath expression in test instead of complex eval expression
- use classList instead of className
parent 25ebd6b6
...@@ -510,6 +510,7 @@ ...@@ -510,6 +510,7 @@
data_explore, data_explore,
new_state = {}, new_state = {},
tag_name = evt.target.tagName.toLowerCase(); tag_name = evt.target.tagName.toLowerCase();
if (tag_name === 'button') { if (tag_name === 'button') {
// Go to the search listbox // Go to the search listbox
return redirectToTheSearchListbox(gadget); return redirectToTheSearchListbox(gadget);
...@@ -557,7 +558,7 @@ ...@@ -557,7 +558,7 @@
if (evt.key === "ArrowDown" || evt.key === "ArrowUp") { if (evt.key === "ArrowDown" || evt.key === "ArrowUp") {
if (ul.childNodes.length > 0) { if (ul.childNodes.length > 0) {
for (i = 0; i < ul.childNodes.length; i += 1) { for (i = 0; i < ul.childNodes.length; i += 1) {
if (ul.childNodes[i].className.endsWith('active')) { if (ul.childNodes[i].classList.contains('active')) {
active_index = i; active_index = i;
} }
} }
...@@ -582,14 +583,12 @@ ...@@ -582,14 +583,12 @@
} }
for (i = 0; i < ul.childNodes.length; i += 1) { for (i = 0; i < ul.childNodes.length; i += 1) {
if (i === active_index) { if (i === active_index) {
if (!ul.childNodes[i].className.endsWith("active")) { if (!ul.childNodes[i].classList.contains('active')) {
ul.childNodes[i].className = ul.childNodes[i].className + ul.childNodes[i].classList.add('active');
" active";
} }
} else { } else {
if (ul.childNodes[i].className.endsWith("active")) { if (ul.childNodes[i].classList.contains('active')) {
ul.childNodes[i].className = ul.childNodes[i].className.replace( ul.childNodes[i].classList.remove('active');
" active", "");
} }
} }
} }
...@@ -597,7 +596,7 @@ ...@@ -597,7 +596,7 @@
} }
} else if (evt.key === "Enter") { } else if (evt.key === "Enter") {
for (i = 0; i < ul.childNodes.length; i += 1) { for (i = 0; i < ul.childNodes.length; i += 1) {
if (ul.childNodes[i].className.endsWith('active')) { if (ul.childNodes[i].classList.contains('active')) {
next_event = new MouseEvent('click', { next_event = new MouseEvent('click', {
view: window, view: window,
bubbles: true, bubbles: true,
...@@ -618,13 +617,11 @@ ...@@ -618,13 +617,11 @@
ul = gadget.element.querySelector(".search_ul"); ul = gadget.element.querySelector(".search_ul");
if (evt.target.tagName.toLowerCase() === 'li') { if (evt.target.tagName.toLowerCase() === 'li') {
for (i = 0; i < ul.childNodes.length; i += 1) { for (i = 0; i < ul.childNodes.length; i += 1) {
ul.childNodes[i].className = ul.childNodes[i].className.replace( ul.childNodes[i].classList.remove('active');
" active", "");
} }
evt.target.className = evt.target.className + " active"; evt.target.classList.add('active');
} }
}, true, false) }, true, false)
.declareAcquiredMethod("notifyBlur", "notifyBlur") .declareAcquiredMethod("notifyBlur", "notifyBlur")
.onEvent('blur', function (evt) { .onEvent('blur', function (evt) {
var gadget = this; var gadget = this;
......
...@@ -11,9 +11,13 @@ ...@@ -11,9 +11,13 @@
<value> <value>
<object> <object>
<klass> <klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/> <global name="_reconstructor" module="copy_reg"/>
</klass> </klass>
<tuple/> <tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state> <state>
<dictionary> <dictionary>
<item> <item>
......
...@@ -77,14 +77,14 @@ ...@@ -77,14 +77,14 @@
<!-- We have class "active" for every line that should be highlighted --> <!-- We have class "active" for every line that should be highlighted -->
<!-- Initially, no lines are highlighted --> <!-- Initially, no lines are highlighted -->
<tr> <tr>
<td>assertEval</td> <td>assertElementNotPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[0].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>false</td> <td></td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>assertElementNotPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[1].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=2 and contains(@class,'active')]</td>
<td>false</td> <td></td>
</tr> </tr>
<!-- We do Arrow down key, then first line should be highlighted --> <!-- We do Arrow down key, then first line should be highlighted -->
<tr> <tr>
...@@ -94,14 +94,19 @@ ...@@ -94,14 +94,19 @@
<td>true</td> <td>true</td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>waitForElementPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[0].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>true</td> <td></td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>assertElementPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[1].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>false</td> <td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=2 and contains(@class,'active')]</td>
<td></td>
</tr> </tr>
<!-- We do Arrow down key again, then second line should be highlighted --> <!-- We do Arrow down key again, then second line should be highlighted -->
<tr> <tr>
...@@ -111,14 +116,19 @@ ...@@ -111,14 +116,19 @@
<td>true</td> <td>true</td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>waitForElementPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[0].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=2 and contains(@class,'active')]</td>
<td>false</td> <td></td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>assertElementNotPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[1].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>true</td> <td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=2 and contains(@class,'active')]</td>
<td></td>
</tr> </tr>
<!-- We do Arrow up key, then first line should be highlighted --> <!-- We do Arrow up key, then first line should be highlighted -->
<tr> <tr>
...@@ -128,14 +138,19 @@ ...@@ -128,14 +138,19 @@
<td>true</td> <td>true</td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>waitForElementPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[1].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>false</td> <td></td>
</tr> </tr>
<tr> <tr>
<td>assertEval</td> <td>assertElementPresent</td>
<td>(function() {return selenium.browserbot.getCurrentWindow().document.querySelector("input[name='field_my_foo_category_title']").parentNode.querySelectorAll('li')[0].className.endsWith("active")})() <td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=1 and contains(@class,'active')]</td>
<td>true</td> <td></td>
</tr>
<tr>
<td>assertElementNotPresent</td>
<td>//input[@name='field_my_foo_category_title']/parent::*//li[position()=2 and contains(@class,'active')]</td>
<td></td>
</tr> </tr>
<!-- Make sure Enter key allows to validate the selected line and disable the list of choice --> <!-- Make sure Enter key allows to validate the selected line and disable the list of choice -->
<tr> <tr>
...@@ -154,6 +169,12 @@ ...@@ -154,6 +169,12 @@
<td>//input[@name='field_my_foo_category_title']</td> <td>//input[@name='field_my_foo_category_title']</td>
<td>Quantity</td> <td>Quantity</td>
</tr> </tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/save" />
<tr>
<td>assertValue</td>
<td>//input[@name='field_my_foo_category_title']</td>
<td>Quantity</td>
</tr>
</tbody></table> </tbody></table>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment