From 916aeb4526e921b429e0575d7a2cb3e9fffdce98 Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Thu, 29 Aug 2024 20:00:12 +0000 Subject: [PATCH 1/3] Update disabled pseudo-classes test from WPT --- .../selectors/pseudo-classes/disabled.html | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html b/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html index 8808675..f665348 100644 --- a/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html +++ b/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html @@ -57,4 +57,24 @@ var input = document.createElement("input"); input.setAttribute("disabled", "disabled"); testSelectorIdsMatch(":disabled", ["button1", "input2", "select2", "optgroup2", "option2", "textarea2", "fieldset2", "clubname", "clubnum"], "':disabled' should not match elements not in the document"); - + + var fieldset = document.createElement("fieldset"); + fieldset.id = "fieldset_nested"; + fieldset.innerHTML = ` + + + + + + +
+ +
+ `; + document.getElementById("fieldset2").appendChild(fieldset); + testSelectorIdsMatch("#fieldset2 :disabled", ["clubname", "clubnum", "fieldset_nested", "input_nested", "button_nested", "select_nested", "textarea_nested", "fieldset_nested2", "input_nested2"], "':disabled' should match elements that are appended to a disabled fieldset dynamically"); + \ No newline at end of file From 0658d6427a4bcfd3eb7367d82ea46fc2f02793b7 Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Thu, 29 Aug 2024 20:04:42 +0000 Subject: [PATCH 2/3] Implement nested fieldset support for disabled --- src/nwsapi.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/nwsapi.js b/src/nwsapi.js index dd92116..f10ce66 100644 --- a/src/nwsapi.js +++ b/src/nwsapi.js @@ -1123,10 +1123,31 @@ ')){' + source + '}'; break; case 'disabled': - // https://www.w3.org/TR/html5/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute - source = 'if((("form" in e||/^optgroup$/i.test(e.localName))&&"disabled" in e&&' + - '(e.disabled===true||(n=s.ancestor("fieldset",e))&&(n=s.first("legend",n))&&!n.contains(e))' + - ')){' + source + '}'; + // https://html.spec.whatwg.org/#enabling-and-disabling-form-controls:-the-disabled-attribute + source = 'if((("form" in e||/^optgroup$/i.test(e.localName))&&"disabled" in e)){' + + // F is true if any of the fieldset elements in the ancestry chain has the disabled attribute specified + // L is true if the first legend element of the fieldset contains the element + 'var x=0,N=[],F=false,L=false;' + + 'if(!(/^(optgroup|option)$/i.test(e.localName))){' + + 'n=e.parentElement;' + + 'while(n){' + + 'if(n.localName=="fieldset"){' + + 'N[x++]=n;' + + 'if(n.disabled===true){' + + 'F=true;' + + 'break;' + + '}' + + '}' + + 'n=n.parentElement;' + + '}' + + 'for(var x=0;x Date: Thu, 29 Aug 2024 20:12:36 +0000 Subject: [PATCH 3/3] Add new line --- test/w3c/html/semantics/selectors/pseudo-classes/disabled.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html b/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html index f665348..142a12d 100644 --- a/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html +++ b/test/w3c/html/semantics/selectors/pseudo-classes/disabled.html @@ -77,4 +77,4 @@ `; document.getElementById("fieldset2").appendChild(fieldset); testSelectorIdsMatch("#fieldset2 :disabled", ["clubname", "clubnum", "fieldset_nested", "input_nested", "button_nested", "select_nested", "textarea_nested", "fieldset_nested2", "input_nested2"], "':disabled' should match elements that are appended to a disabled fieldset dynamically"); - \ No newline at end of file +