button-event-dispatch-content-attribute.html (1523B)
1 <!doctype html> 2 <meta charset="utf-8" /> 3 <meta name="author" title="Keith Cirkel" href="mailto:wpt@keithcirkel.co.uk" /> 4 <meta name="timeout" content="long" /> 5 <link rel="help" href="https://open-ui.org/components/invokers.explainer/" /> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="resources/invoker-utils.js"></script> 9 10 <button 11 id="invokerbutton" 12 commandfor="invokee" 13 command="--custom-command" 14 ></button> 15 <input 16 type="number" 17 id="invokee" 18 oncommand="this.value = Number(this.value) + 1" 19 value="0" 20 /> 21 <div popover id="popover" oncommand="return false"></div> 22 23 <script> 24 test(function (t) { 25 assert_true( 26 typeof invokee.oncommand == "function", 27 "invokee has an oncommand function", 28 ); 29 assert_equals(invokee.valueAsNumber, 0, "input is equal to 0"); 30 invokerbutton.click(); 31 assert_equals(invokee.valueAsNumber, 1, "input is equal to 1"); 32 }, "oncommand content attribute works"); 33 34 test(function (t) { 35 t.add_cleanup(() => { 36 invokerbutton.command = "--custom-command"; 37 }); 38 invokerbutton.command = "show-popover"; 39 assert_true( 40 typeof popover.oncommand == "function", 41 "invokee has an oncommand function", 42 ); 43 assert_false(popover.matches(":popover-open"), "popover is not open"); 44 invokerbutton.click(); 45 assert_false(popover.matches(":popover-open"), "popover is still not open"); 46 }, "oncommand content with a value of false prevents default"); 47 </script>