Skip to content

Commit a88faef

Browse files
twalpoleshs96c
authored andcommitted
implement disabled fieldset support
Signed-off-by: Simon Stewart <simon.m.stewart@gmail.com>
1 parent 5f7eef6 commit a88faef

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

javascript/atoms/dom.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,35 @@ bot.dom.isEnabled = function(el) {
330330
goog.dom.TagName.OPTION == tagName) {
331331
return bot.dom.isEnabled((/**@type{!Element}*/el.parentNode));
332332
}
333+
334+
// Is there an ancestor of the current element that is a disabled fieldset
335+
// and whose child is also an ancestor-or-self of the current element but is
336+
// not the first legend child of the fieldset. If so then the element is
337+
// disabled.
338+
if (goog.dom.getAncestor(el, function (e) {
339+
var parent = e.parentNode;
340+
341+
if (parent &&
342+
bot.dom.isElement(parent, goog.dom.TagName.FIELDSET) &&
343+
bot.dom.getProperty(parent, 'disabled')) {
344+
if (!bot.dom.isElement(e, goog.dom.TagName.LEGEND)) {
345+
return true;
346+
}
347+
348+
var sibling = e;
349+
// Are there any previous legend siblings? If so then we are not the
350+
// first and the element is disabled
351+
while (sibling = goog.dom.getPreviousElementSibling(sibling)) {
352+
if (bot.dom.isElement(sibling, goog.dom.TagName.LEGEND)) {
353+
return true;
354+
}
355+
}
356+
}
357+
return false;
358+
}, true)) {
359+
return false;
360+
}
361+
333362
return true;
334363
};
335364

javascript/atoms/test/enabled_test.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
assertDisabled('inherits-disabled-2');
4848
}
4949

50+
function testDisabledShouldInheritFromFieldsetUnlessInLegend() {
51+
assertDisabled('disabled-fieldset-button-g');
52+
assertEnabled('legend-button-f');
53+
}
54+
5055
function testEnabledShouldRespondToDisabledProperty() {
5156
var element = goog.dom.$('enabled-button-a');
5257
element.disabled = true;
@@ -79,6 +84,13 @@
7984
<option id="inherits-disabled-2">baz</option>
8085
</optgroup>
8186
</select>
87+
88+
<fieldset id="disabled-fieldset" disabled="disabled">
89+
<legend>
90+
<button id="legend-button-f" value="Enabled F"></button>
91+
</legend>
92+
<button id="disabled-fieldset-button-g" value="Enabled G"></button>
93+
</fieldset>
8294
</form>
8395
</body>
8496
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy