You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
919 lines
57 KiB
919 lines
57 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html lang="en-US-x-Hixie" ><head><title>4.11 Interactive elements — HTML5 </title><style type="text/css">
|
|
pre { margin-left: 2em; white-space: pre-wrap; }
|
|
h2 { margin: 3em 0 1em 0; }
|
|
h3 { margin: 2.5em 0 1em 0; }
|
|
h4 { margin: 2.5em 0 0.75em 0; }
|
|
h5, h6 { margin: 2.5em 0 1em; }
|
|
h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
|
|
h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
|
|
p { margin: 1em 0; }
|
|
hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
|
|
dl, dd { margin-top: 0; margin-bottom: 0; }
|
|
dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
|
|
dt + dt { margin-top: 0; }
|
|
dd dt { margin-top: 0.25em; margin-bottom: 0; }
|
|
dd p { margin-top: 0; }
|
|
dd dl + p { margin-top: 1em; }
|
|
dd table + p { margin-top: 1em; }
|
|
p + * > li, dd li { margin: 1em 0; }
|
|
dt, dfn { font-weight: bold; font-style: normal; }
|
|
dt dfn { font-style: italic; }
|
|
pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
|
|
pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
|
|
pre em { font-weight: bolder; font-style: normal; }
|
|
@media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
|
|
var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
|
|
table { border-collapse: collapse; border-style: hidden hidden none hidden; }
|
|
table thead, table tbody { border-bottom: solid; }
|
|
table tbody th:first-child { border-left: solid; }
|
|
table tbody th { text-align: left; }
|
|
table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
|
|
blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }
|
|
|
|
.bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
|
|
.matrix, .matrix td { border: none; text-align: right; }
|
|
.matrix { margin-left: 2em; }
|
|
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
|
|
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
|
|
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
|
|
|
|
.toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
|
|
img.extra { float: right; }
|
|
pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
|
|
pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
|
|
pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
|
|
pre.css:first-line { color: #AAAA50; }
|
|
dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
|
|
hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
|
|
dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
|
|
dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
|
|
dl.domintro dd p { margin: 0.5em 0; }
|
|
dl.switch { padding-left: 2em; }
|
|
dl.switch > dt { text-indent: -1.5em; }
|
|
dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
|
|
dl.triple { padding: 0 0 0 1em; }
|
|
dl.triple dt, dl.triple dd { margin: 0; display: inline }
|
|
dl.triple dt:after { content: ':'; }
|
|
dl.triple dd:after { content: '\A'; white-space: pre; }
|
|
.diff-old { text-decoration: line-through; color: silver; background: transparent; }
|
|
.diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
|
|
a .diff-new { border-bottom: 1px blue solid; }
|
|
|
|
h2 { page-break-before: always; }
|
|
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
|
|
h1 + h2, hr + h2.no-toc { page-break-before: auto; }
|
|
|
|
p > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]),
|
|
li > span:not([title=""]):not([class="XXX"]):not([class="impl"]):not([class="note"]), { border-bottom: solid #9999CC; }
|
|
|
|
div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
|
|
div.head p { margin: 0; }
|
|
div.head h1 { margin: 0; }
|
|
div.head .logo { float: right; margin: 0 1em; }
|
|
div.head .logo img { border: none } /* remove border from top image */
|
|
div.head dl { margin: 1em 0; }
|
|
div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }
|
|
|
|
body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
|
|
body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
|
|
body > .toc > li > * { margin-bottom: 0.5em; }
|
|
body > .toc > li > * > li > * { margin-bottom: 0.25em; }
|
|
.toc, .toc li { list-style: none; }
|
|
|
|
.brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
|
|
.brief li { margin: 0; padding: 0; }
|
|
.brief li p { margin: 0; padding: 0; }
|
|
|
|
.category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
|
|
.category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
|
|
.category-list li { display: inline; }
|
|
.category-list li:not(:last-child)::after { content: ', '; }
|
|
.category-list li > span, .category-list li > a { text-transform: lowercase; }
|
|
.category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */
|
|
|
|
.XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
|
|
.XXX > :first-child { margin-top: 0; }
|
|
p .XXX { line-height: 3em; }
|
|
.annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
|
|
.annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
|
|
.annotation :link, .annotation :visited { color: inherit; }
|
|
.annotation :link:hover, .annotation :visited:hover { background: transparent; }
|
|
.annotation span { border: none ! important; }
|
|
.note { color: green; background: transparent; font-family: sans-serif; }
|
|
.warning { color: red; background: transparent; }
|
|
.note, .warning { font-weight: bolder; font-style: italic; }
|
|
p.note, div.note { padding: 0.5em 2em; }
|
|
span.note { padding: 0 2em; }
|
|
.note p:first-child, .warning p:first-child { margin-top: 0; }
|
|
.note p:last-child, .warning p:last-child { margin-bottom: 0; }
|
|
.warning:before { font-style: normal; }
|
|
p.note:before { content: 'Note: '; }
|
|
p.warning:before { content: '\26A0 Warning! '; }
|
|
|
|
.bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
|
|
.bookkeeping { font-size: 0.8em; margin: 2em 0; }
|
|
.bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }
|
|
.bookkeeping dt { margin: 0.5em 2em 0; }
|
|
.bookkeeping dd { margin: 0 3em 0.5em; }
|
|
|
|
h4 { position: relative; z-index: 3; }
|
|
h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
|
|
.element {
|
|
background: #EEEEFF;
|
|
color: black;
|
|
margin: 0 0 1em 0.15em;
|
|
padding: 0 1em 0.25em 0.75em;
|
|
border-left: solid #9999FF 0.25em;
|
|
position: relative;
|
|
z-index: 1;
|
|
}
|
|
.element:before {
|
|
position: absolute;
|
|
z-index: 2;
|
|
top: 0;
|
|
left: -1.15em;
|
|
height: 2em;
|
|
width: 0.9em;
|
|
background: #EEEEFF;
|
|
content: ' ';
|
|
border-style: none none solid solid;
|
|
border-color: #9999FF;
|
|
border-width: 0.25em;
|
|
}
|
|
|
|
.example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
|
|
td > .example:only-child { margin: 0 0 0 0.1em; }
|
|
|
|
ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
|
|
ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
|
|
ul.domTree li li { list-style: none; }
|
|
ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
|
|
ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
|
|
ul.domTree span { font-style: italic; font-family: serif; }
|
|
ul.domTree .t1 code { color: purple; font-weight: bold; }
|
|
ul.domTree .t2 { font-style: normal; font-family: monospace; }
|
|
ul.domTree .t2 .name { color: black; font-weight: bold; }
|
|
ul.domTree .t2 .value { color: blue; font-weight: normal; }
|
|
ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
|
|
ul.domTree .t7 code, .domTree .t8 code { color: green; }
|
|
ul.domTree .t10 code { color: teal; }
|
|
|
|
body.dfnEnabled dfn { cursor: pointer; }
|
|
.dfnPanel {
|
|
display: inline;
|
|
position: absolute;
|
|
z-index: 10;
|
|
height: auto;
|
|
width: auto;
|
|
padding: 0.5em 0.75em;
|
|
font: small sans-serif, Droid Sans Fallback;
|
|
background: #DDDDDD;
|
|
color: black;
|
|
border: outset 0.2em;
|
|
}
|
|
.dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
|
|
.dfnPanel :link, .dfnPanel :visited { color: black; }
|
|
.dfnPanel p { font-weight: bolder; }
|
|
.dfnPanel * + p { margin-top: 0.25em; }
|
|
.dfnPanel li { list-style-position: inside; }
|
|
|
|
#configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
|
|
#configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
|
|
#configUI p label { display: block; }
|
|
#configUI #updateUI, #configUI .loginUI { text-align: center; }
|
|
#configUI input[type=button] { display: block; margin: auto; }
|
|
|
|
fieldset { margin: 1em; padding: 0.5em 1em; }
|
|
fieldset > legend + * { margin-top: 0; }
|
|
fieldset > :last-child { margin-bottom: 0; }
|
|
fieldset p { margin: 0.5em 0; }
|
|
|
|
.stability {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0; right: 0;
|
|
margin: 0 auto 0 auto !important;
|
|
z-index: 1000;
|
|
width: 50%;
|
|
background: maroon; color: yellow;
|
|
-webkit-border-radius: 1em 1em 0 0;
|
|
-moz-border-radius: 1em 1em 0 0;
|
|
border-radius: 1em 1em 0 0;
|
|
-moz-box-shadow: 0 0 1em #500;
|
|
-webkit-box-shadow: 0 0 1em #500;
|
|
box-shadow: 0 0 1em red;
|
|
padding: 0.5em 1em;
|
|
text-align: center;
|
|
}
|
|
.stability strong {
|
|
display: block;
|
|
}
|
|
.stability input {
|
|
appearance: none; margin: 0; border: 0; padding: 0.25em 0.5em; background: transparent; color: black;
|
|
position: absolute; top: -0.5em; right: 0; font: 1.25em sans-serif; text-align: center;
|
|
}
|
|
.stability input:hover {
|
|
color: white;
|
|
text-shadow: 0 0 2px black;
|
|
}
|
|
.stability input:active {
|
|
padding: 0.3em 0.45em 0.2em 0.55em;
|
|
}
|
|
.stability :link, .stability :visited,
|
|
.stability :link:hover, .stability :visited:hover {
|
|
background: transparent;
|
|
color: white;
|
|
}
|
|
|
|
</style><link href="data:text/css,.impl%20%7B%20display:%20none;%20%7D%0Ahtml%20%7B%20border:%20solid%20yellow;%20%7D%20.domintro:before%20%7B%20display:%20none;%20%7D" id="author" rel="alternate stylesheet" title="Author documentation only"><link href="data:text/css,.impl%20%7B%20background:%20%23FFEEEE;%20%7D%20.domintro:before%20%7B%20background:%20%23FFEEEE;%20%7D" id="highlight" rel="alternate stylesheet" title="Highlight implementation
|
|
requirements"><link href="http://www.w3.org/StyleSheets/TR/W3C-WD" rel="stylesheet" type="text/css"><style type="text/css">
|
|
|
|
.applies thead th > * { display: block; }
|
|
.applies thead code { display: block; }
|
|
.applies tbody th { whitespace: nowrap; }
|
|
.applies td { text-align: center; }
|
|
.applies .yes { background: yellow; }
|
|
|
|
.matrix, .matrix td { border: hidden; text-align: right; }
|
|
.matrix { margin-left: 2em; }
|
|
|
|
.dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
|
|
.dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
|
|
.dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }
|
|
|
|
td.eg { border-width: thin; text-align: center; }
|
|
|
|
#table-example-1 { border: solid thin; border-collapse: collapse; margin-left: 3em; }
|
|
#table-example-1 * { font-family: "Essays1743", serif; line-height: 1.01em; }
|
|
#table-example-1 caption { padding-bottom: 0.5em; }
|
|
#table-example-1 thead, #table-example-1 tbody { border: none; }
|
|
#table-example-1 th, #table-example-1 td { border: solid thin; }
|
|
#table-example-1 th { font-weight: normal; }
|
|
#table-example-1 td { border-style: none solid; vertical-align: top; }
|
|
#table-example-1 th { padding: 0.5em; vertical-align: middle; text-align: center; }
|
|
#table-example-1 tbody tr:first-child td { padding-top: 0.5em; }
|
|
#table-example-1 tbody tr:last-child td { padding-bottom: 1.5em; }
|
|
#table-example-1 tbody td:first-child { padding-left: 2.5em; padding-right: 0; width: 9em; }
|
|
#table-example-1 tbody td:first-child::after { content: leader(". "); }
|
|
#table-example-1 tbody td { padding-left: 2em; padding-right: 2em; }
|
|
#table-example-1 tbody td:first-child + td { width: 10em; }
|
|
#table-example-1 tbody td:first-child + td ~ td { width: 2.5em; }
|
|
#table-example-1 tbody td:first-child + td + td + td ~ td { width: 1.25em; }
|
|
|
|
.apple-table-examples { border: none; border-collapse: separate; border-spacing: 1.5em 0em; width: 40em; margin-left: 3em; }
|
|
.apple-table-examples * { font-family: "Times", serif; }
|
|
.apple-table-examples td, .apple-table-examples th { border: none; white-space: nowrap; padding-top: 0; padding-bottom: 0; }
|
|
.apple-table-examples tbody th:first-child { border-left: none; width: 100%; }
|
|
.apple-table-examples thead th:first-child ~ th { font-size: smaller; font-weight: bolder; border-bottom: solid 2px; text-align: center; }
|
|
.apple-table-examples tbody th::after, .apple-table-examples tfoot th::after { content: leader(". ") }
|
|
.apple-table-examples tbody th, .apple-table-examples tfoot th { font: inherit; text-align: left; }
|
|
.apple-table-examples td { text-align: right; vertical-align: top; }
|
|
.apple-table-examples.e1 tbody tr:last-child td { border-bottom: solid 1px; }
|
|
.apple-table-examples.e1 tbody + tbody tr:last-child td { border-bottom: double 3px; }
|
|
.apple-table-examples.e2 th[scope=row] { padding-left: 1em; }
|
|
.apple-table-examples sup { line-height: 0; }
|
|
|
|
.details-example img { vertical-align: top; }
|
|
|
|
#base64-table {
|
|
white-space: nowrap;
|
|
font-size: 0.6em;
|
|
column-width: 6em;
|
|
column-count: 5;
|
|
column-gap: 1em;
|
|
-moz-column-width: 6em;
|
|
-moz-column-count: 5;
|
|
-moz-column-gap: 1em;
|
|
-webkit-column-width: 6em;
|
|
-webkit-column-count: 5;
|
|
-webkit-column-gap: 1em;
|
|
}
|
|
#base64-table thead { display: none; }
|
|
#base64-table * { border: none; }
|
|
#base64-table tbody td:first-child:after { content: ':'; }
|
|
#base64-table tbody td:last-child { text-align: right; }
|
|
|
|
#named-character-references-table {
|
|
white-space: nowrap;
|
|
font-size: 0.6em;
|
|
column-width: 30em;
|
|
column-gap: 1em;
|
|
-moz-column-width: 30em;
|
|
-moz-column-gap: 1em;
|
|
-webkit-column-width: 30em;
|
|
-webkit-column-gap: 1em;
|
|
}
|
|
#named-character-references-table > table > tbody > tr > td:first-child + td,
|
|
#named-character-references-table > table > tbody > tr > td:last-child { text-align: center; }
|
|
#named-character-references-table > table > tbody > tr > td:last-child:hover > span { position: absolute; top: auto; left: auto; margin-left: 0.5em; line-height: 1.2; font-size: 5em; border: outset; padding: 0.25em 0.5em; background: white; width: 1.25em; height: auto; text-align: center; }
|
|
#named-character-references-table > table > tbody > tr#entity-CounterClockwiseContourIntegral > td:first-child { font-size: 0.5em; }
|
|
|
|
.glyph.control { color: red; }
|
|
|
|
@font-face {
|
|
font-family: 'Essays1743';
|
|
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743.ttf');
|
|
}
|
|
@font-face {
|
|
font-family: 'Essays1743';
|
|
font-weight: bold;
|
|
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Bold.ttf');
|
|
}
|
|
@font-face {
|
|
font-family: 'Essays1743';
|
|
font-style: italic;
|
|
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-Italic.ttf');
|
|
}
|
|
@font-face {
|
|
font-family: 'Essays1743';
|
|
font-style: italic;
|
|
font-weight: bold;
|
|
src: url('http://www.whatwg.org/specs/web-apps/current-work/fonts/Essays1743-BoldItalic.ttf');
|
|
}
|
|
|
|
</style><style type="text/css">
|
|
.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: black; font-style: italic; border: solid 2px; background: white; padding: 0 0.25em; }
|
|
</style><script type="text/javascript">
|
|
function getCookie(name) {
|
|
var params = location.search.substr(1).split("&");
|
|
for (var index = 0; index < params.length; index++) {
|
|
if (params[index] == name)
|
|
return "1";
|
|
var data = params[index].split("=");
|
|
if (data[0] == name)
|
|
return unescape(data[1]);
|
|
}
|
|
var cookies = document.cookie.split("; ");
|
|
for (var index = 0; index < cookies.length; index++) {
|
|
var data = cookies[index].split("=");
|
|
if (data[0] == name)
|
|
return unescape(data[1]);
|
|
}
|
|
return null;
|
|
}
|
|
</script>
|
|
<script src="link-fixup.js" type="text/javascript"></script>
|
|
<link href="style.css" rel="stylesheet"><link href="association-of-controls-and-forms.html" title="4.10.18 Association of controls and forms" rel="prev">
|
|
<link href="spec.html#contents" title="Table of contents" rel="index">
|
|
<link href="commands.html" title="4.11.5 Commands" rel="next">
|
|
</head><body><div class="head" id="head">
|
|
<div id="multipage-common">
|
|
<p class="stability" id="wip"><strong>This is a work in
|
|
progress!</strong> For the latest updates from the HTML WG, possibly
|
|
including important bug fixes, please look at the <a href="http://dev.w3.org/html5/spec/Overview.html">editor's draft</a> instead.
|
|
There may also be a more
|
|
<a href="http://www.w3.org/TR/html5">up-to-date Working Draft</a>
|
|
with changes based on resolution of Last Call issues.
|
|
<input onclick="closeWarning(this.parentNode)" type="button" value="╳⃝"></p>
|
|
<script type="text/javascript">
|
|
function closeWarning(element) {
|
|
element.parentNode.removeChild(element);
|
|
var date = new Date();
|
|
date.setDate(date.getDate()+4);
|
|
document.cookie = 'hide-obsolescence-warning=1; expires=' + date.toGMTString();
|
|
}
|
|
if (getCookie('hide-obsolescence-warning') == '1')
|
|
setTimeout(function () { document.getElementById('wip').parentNode.removeChild(document.getElementById('wip')); }, 2000);
|
|
</script></div>
|
|
|
|
<p><a href="http://www.w3.org/"><img alt="W3C" height="48" src="http://www.w3.org/Icons/w3c_home" width="72"></a></p>
|
|
|
|
<h1>HTML5</h1>
|
|
</div><div>
|
|
<a href="association-of-controls-and-forms.html" class="prev">4.10.18 Association of controls and forms</a> –
|
|
<a href="spec.html#contents">Table of contents</a> –
|
|
<a href="commands.html" class="next">4.11.5 Commands</a>
|
|
<ol class="toc"><li><ol><li><a href="interactive-elements.html#interactive-elements"><span class="secno">4.11 </span>Interactive elements</a>
|
|
<ol><li><a href="interactive-elements.html#the-details-element"><span class="secno">4.11.1 </span>The <code>details</code> element</a></li><li><a href="interactive-elements.html#the-summary-element"><span class="secno">4.11.2 </span>The <code>summary</code> element</a></li><li><a href="interactive-elements.html#the-command-element"><span class="secno">4.11.3 </span>The <code>command</code> element</a></li><li><a href="interactive-elements.html#the-menu-element"><span class="secno">4.11.4 </span>The <code>menu</code> element</a>
|
|
<ol><li><a href="interactive-elements.html#menus-intro"><span class="secno">4.11.4.1 </span>Introduction</a></li><li><a href="interactive-elements.html#building-menus-and-toolbars"><span class="secno">4.11.4.2 </span>Building menus and toolbars</a></li><li><a href="interactive-elements.html#context-menus"><span class="secno">4.11.4.3 </span>Context menus</a></li><li><a href="interactive-elements.html#toolbars"><span class="secno">4.11.4.4 </span>Toolbars</a></li></ol></li></ol></li></ol></li></ol></div>
|
|
|
|
<h3 id="interactive-elements"><span class="secno">4.11 </span>Interactive elements</h3><h4 id="the-details-element"><span class="secno">4.11.1 </span>The <dfn><code>details</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
|
|
<dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
|
|
<dd><a href="sections.html#sectioning-root">Sectioning root</a>.</dd>
|
|
<dd><a href="content-models.html#interactive-content">Interactive content</a>.</dd>
|
|
<dt>Contexts in which this element can be used:</dt>
|
|
<dd>Where <a href="content-models.html#flow-content">flow content</a> is expected.</dd>
|
|
<dt>Content model:</dt>
|
|
<dd>One <code><a href="#the-summary-element">summary</a></code> element followed by <a href="content-models.html#flow-content">flow content</a>.</dd>
|
|
<dt>Content attributes:</dt>
|
|
<dd><a href="elements.html#global-attributes">Global attributes</a></dd>
|
|
<dd><code title="attr-details-open"><a href="#attr-details-open">open</a></code></dd>
|
|
<dt>DOM interface:</dt>
|
|
<dd>
|
|
<pre class="idl">interface <dfn id="htmldetailselement">HTMLDetailsElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
|
|
attribute boolean <a href="#dom-details-open" title="dom-details-open">open</a>;
|
|
};</pre>
|
|
</dd>
|
|
</dl><p>The <code><a href="#the-details-element">details</a></code> element <a href="rendering.html#represents">represents</a> a
|
|
disclosure widget from which the user can obtain additional
|
|
information or controls.</p><p class="note">The <code><a href="#the-details-element">details</a></code> element is not appropriate
|
|
for footnotes. Please see <a href="links.html#footnotes">the section on
|
|
footnotes</a> for details on how to mark up footnotes.</p><p>The <span class="impl">first</span> <code><a href="#the-summary-element">summary</a></code> element
|
|
child of the element, if any, <a href="rendering.html#represents">represents</a> the summary or
|
|
legend of the details. <span class="impl">If there is no child
|
|
<code><a href="#the-summary-element">summary</a></code> element, the user agent should provide its own
|
|
legend (e.g. "Details").</span></p><p>The <dfn id="attr-details-open" title="attr-details-open"><code>open</code></dfn>
|
|
content attribute is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a>. If present,
|
|
it indicates that the details are to be shown to the user. If the
|
|
attribute is absent, the details are not to be shown.</p><div class="impl">
|
|
|
|
<p>When the element is created, if the attribute is absent, the
|
|
details should be hidden; if the attribute is absent, the details
|
|
should be shown. Subsequently, if the attribute is removed, then the
|
|
details should be hidden; if the attribute is added, the details
|
|
should be shown.</p>
|
|
|
|
<p>The user agent should allow the user to request that the details
|
|
be shown or hidden. To honor a request for the details to be shown,
|
|
the user agent must set the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> attribute on the element to
|
|
the value <code title="">open</code>. To honor a request for the
|
|
details to be hidden, the user agent must remove the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> attribute from the
|
|
element.</p>
|
|
|
|
<p>The <dfn id="dom-details-open" title="dom-details-open"><code>open</code></dfn> IDL
|
|
attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the <code title="attr-details-open"><a href="#attr-details-open">open</a></code> content attribute.</p>
|
|
|
|
</div><div class="example">
|
|
|
|
<p>The following example shows the <code><a href="#the-details-element">details</a></code> element
|
|
being used to hide technical details in a progress report.</p>
|
|
|
|
<pre><section class="progress window">
|
|
<h1>Copying "Really Achieving Your Childhood Dreams"</h1>
|
|
<details>
|
|
<summary>Copying... <progress max="375505392" value="97543282"></progress> 25%</summary>
|
|
<dl>
|
|
<dt>Transfer rate:</dt> <dd>452KB/s</dd>
|
|
<dt>Local filename:</dt> <dd>/home/rpausch/raycd.m4v</dd>
|
|
<dt>Remote filename:</dt> <dd>/var/www/lectures/raycd.m4v</dd>
|
|
<dt>Duration:</dt> <dd>01:16:27</dd>
|
|
<dt>Color profile:</dt> <dd>SD (6-1-6)</dd>
|
|
<dt>Dimensions:</dt> <dd>320×240</dd>
|
|
</dl>
|
|
</details>
|
|
</section></pre>
|
|
|
|
</div><div class="example">
|
|
|
|
<p>The following shows how a <code><a href="#the-details-element">details</a></code> element can be
|
|
used to hide some controls by default:</p>
|
|
|
|
<pre><details>
|
|
<summary><label for=fn>Name & Extension:</label></summary>
|
|
<p><input type=text id=fn name=fn value="Pillar Magazine.pdf">
|
|
<p><label><input type=checkbox name=ext checked> Hide extension</label>
|
|
</details></pre>
|
|
|
|
<p>One could use this in conjunction with other <code><a href="#the-details-element">details</a></code>
|
|
in a list to allow the user to collapse a set of fields down to a
|
|
small set of headings, with the ability to open each one.</p>
|
|
|
|
<p class="details-example"><img alt="" height="611" src="sample-details-1.png" width="345"><img alt="" height="666" src="sample-details-2.png" width="345"></p>
|
|
|
|
<p>In these examples, the summary really just summarises what the
|
|
controls can change, and not the actual values, which is less than
|
|
ideal.</p>
|
|
|
|
</div><h4 id="the-summary-element"><span class="secno">4.11.2 </span>The <dfn><code>summary</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
|
|
<dd>None.</dd>
|
|
<dt>Contexts in which this element can be used:</dt>
|
|
<dd>As the first child of a <code><a href="#the-details-element">details</a></code> element.</dd>
|
|
<dt>Content model:</dt>
|
|
<dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
|
|
<dt>Content attributes:</dt>
|
|
<dd><a href="elements.html#global-attributes">Global attributes</a></dd>
|
|
<dt>DOM interface:</dt>
|
|
<dd>Uses <code><a href="elements.html#htmlelement">HTMLElement</a></code>.</dd>
|
|
</dl><p>The <code><a href="#the-summary-element">summary</a></code> element <a href="rendering.html#represents">represents</a> a
|
|
summary, caption, or legend for the rest of the contents of the
|
|
<code><a href="#the-summary-element">summary</a></code> element's parent <code><a href="#the-details-element">details</a></code>
|
|
element<span class="impl">, if any</span>.</p><h4 id="the-command-element"><span class="secno">4.11.3 </span>The <dfn id="the-command"><code>command</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
|
|
<dd><a href="content-models.html#metadata-content">Metadata content</a>.</dd>
|
|
<dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
|
|
<dd><a href="content-models.html#phrasing-content">Phrasing content</a>.</dd>
|
|
<dt>Contexts in which this element can be used:</dt>
|
|
<dd>Where <a href="content-models.html#metadata-content">metadata content</a> is expected.</dd>
|
|
<dd>Where <a href="content-models.html#phrasing-content">phrasing content</a> is expected.</dd>
|
|
<dt>Content model:</dt>
|
|
<dd>Empty.</dd>
|
|
<dt>Content attributes:</dt>
|
|
<dd><a href="elements.html#global-attributes">Global attributes</a></dd>
|
|
<dd><code title="attr-command-type"><a href="#attr-command-type">type</a></code></dd>
|
|
<dd><code title="attr-command-label"><a href="#attr-command-label">label</a></code></dd>
|
|
<dd><code title="attr-command-icon"><a href="#attr-command-icon">icon</a></code></dd>
|
|
<dd><code title="attr-command-disabled"><a href="#attr-command-disabled">disabled</a></code></dd>
|
|
<dd><code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code></dd>
|
|
<dd><code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code></dd>
|
|
|
|
<dd>Also, the <code title="attr-command-title"><a href="#attr-command-title">title</a></code> attribute has special semantics on this element.</dd>
|
|
<dt>DOM interface:</dt>
|
|
<dd>
|
|
<pre class="idl">interface <dfn id="htmlcommandelement">HTMLCommandElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
|
|
attribute DOMString <a href="#dom-command-type" title="dom-command-type">type</a>;
|
|
attribute DOMString <a href="#dom-command-label" title="dom-command-label">label</a>;
|
|
attribute DOMString <a href="#dom-command-icon" title="dom-command-icon">icon</a>;
|
|
attribute boolean <a href="#dom-command-disabled" title="dom-command-disabled">disabled</a>;
|
|
attribute boolean <a href="#dom-command-checked" title="dom-command-checked">checked</a>;
|
|
attribute DOMString <a href="#dom-command-radiogroup" title="dom-command-radiogroup">radiogroup</a>;};</pre>
|
|
</dd>
|
|
</dl><p>The <code><a href="#the-command-element">command</a></code> element represents a command that the user
|
|
can invoke.</p><p>A command can be part of a context menu or toolbar, using the
|
|
<code><a href="#the-menu-element">menu</a></code> element, or can be put anywhere else in the page,
|
|
to define a keyboard shortcut.</p><p>The <dfn id="attr-command-type" title="attr-command-type"><code>type</code></dfn>
|
|
attribute indicates the kind of command: either a normal command
|
|
with an associated action, or a state or option that can be toggled,
|
|
or a selection of one item from a list of items.</p><p>The attribute is an <a href="common-microsyntaxes.html#enumerated-attribute">enumerated attribute</a> with three
|
|
keywords and states. The "<dfn id="attr-command-type-keyword-command" title="attr-command-type-keyword-command"><code>command</code></dfn>"
|
|
keyword maps to the <a href="#attr-command-type-state-command" title="attr-command-type-state-command">Command</a> state, the
|
|
"<dfn id="attr-command-type-keyword-checkbox" title="attr-command-type-keyword-checkbox"><code>checkbox</code></dfn>"
|
|
keyword maps to the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state, and
|
|
the "<dfn id="attr-command-type-keyword-radio" title="attr-command-type-keyword-radio"><code>radio</code></dfn>"
|
|
keyword maps to the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state. The
|
|
<i>missing value default</i> is the <a href="#attr-command-type-state-command" title="attr-command-type-state-command">Command</a> state.</p><dl><dt>The <dfn id="attr-command-type-state-command" title="attr-command-type-state-command">Command</dfn> state</dt>
|
|
|
|
<dd><p>The element <a href="rendering.html#represents">represents</a> a normal command with an associated action.</p></dd>
|
|
|
|
<dt>The <dfn id="attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</dfn> state</dt>
|
|
|
|
<dd><p>The element <a href="rendering.html#represents">represents</a> a state or option that can be toggled.</p></dd>
|
|
|
|
<dt>The <dfn id="attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</dfn> state</dt>
|
|
|
|
<dd><p>The element <a href="rendering.html#represents">represents</a> a selection of one item from a list of items.</p></dd>
|
|
|
|
</dl><p>The <dfn id="attr-command-label" title="attr-command-label"><code>label</code></dfn>
|
|
attribute gives the name of the command, as shown to the user. The
|
|
<code title="attr-command-label"><a href="#attr-command-label">label</a></code> attribute must be
|
|
specified and must have a value that is not the empty string.</p><p>The <dfn id="attr-command-title" title="attr-command-title"><code>title</code></dfn>
|
|
attribute gives a hint describing the command, which might be shown
|
|
to the user to help him.</p><p>The <dfn id="attr-command-icon" title="attr-command-icon"><code>icon</code></dfn>
|
|
attribute gives a picture that represents the command. If the
|
|
attribute is specified, the attribute's value must contain a
|
|
<a href="urls.html#valid-non-empty-url-potentially-surrounded-by-spaces">valid non-empty URL potentially surrounded by
|
|
spaces</a>. <span class="impl">To obtain the <a href="urls.html#absolute-url">absolute
|
|
URL</a> of the icon when the attribute's value is not the empty
|
|
string, the attribute's value must be <a href="urls.html#resolve-a-url" title="resolve a
|
|
url">resolved</a> relative to the element. When the attribute is
|
|
absent, or its value is the empty string, or <a href="urls.html#resolve-a-url" title="resolve a
|
|
url">resolving</a> its value fails, there is no icon.</span></p><p>The <dfn id="attr-command-disabled" title="attr-command-disabled"><code>disabled</code></dfn> attribute
|
|
is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a> that, if present, indicates that
|
|
the command is not available in the current state.</p><p class="note">The distinction between <code title="attr-command-disabled"><a href="#attr-command-disabled">disabled</a></code> and <code title="attr-hidden"><a href="editing.html#the-hidden-attribute">hidden</a></code> is subtle. A command would be
|
|
disabled if, in the same context, it could be enabled if only
|
|
certain aspects of the situation were changed. A command would be
|
|
marked as hidden if, in that situation, the command will never be
|
|
enabled. For example, in the context menu for a water faucet, the
|
|
command "open" might be disabled if the faucet is already open, but
|
|
the command "eat" would be marked hidden since the faucet could
|
|
never be eaten.</p><p>The <dfn id="attr-command-checked" title="attr-command-checked"><code>checked</code></dfn>
|
|
attribute is a <a href="common-microsyntaxes.html#boolean-attribute">boolean attribute</a> that, if present,
|
|
indicates that the command is selected. The attribute must be
|
|
omitted unless the <code title="attr-command-type"><a href="#attr-command-type">type</a></code>
|
|
attribute is in either the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state or
|
|
the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a>
|
|
state.</p><p>The <dfn id="attr-command-radiogroup" title="attr-command-radiogroup"><code>radiogroup</code></dfn>
|
|
attribute gives the name of the group of commands that will be
|
|
toggled when the command itself is toggled, for commands whose <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute has the value "<code title="">radio</code>". The scope of the name is the child list of
|
|
the parent element. The attribute must be omitted unless the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is in the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state.</p><div class="impl">
|
|
|
|
<p>The <dfn id="dom-command-type" title="dom-command-type"><code>type</code></dfn> IDL
|
|
attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the content attribute of the
|
|
same name, <a href="common-dom-interfaces.html#limited-to-only-known-values">limited to only known values</a>.</p>
|
|
|
|
<p>The <dfn id="dom-command-label" title="dom-command-label"><code>label</code></dfn>, <dfn id="dom-command-icon" title="dom-command-icon"><code>icon</code></dfn>, <dfn id="dom-command-disabled" title="dom-command-disabled"><code>disabled</code></dfn>, <dfn id="dom-command-checked" title="dom-command-checked"><code>checked</code></dfn>, and <dfn id="dom-command-radiogroup" title="dom-command-radiogroup"><code>radiogroup</code></dfn> IDL attributes must <a href="common-dom-interfaces.html#reflect">reflect</a> the respective content
|
|
attributes of the same name.</p>
|
|
|
|
<p>The element's <a href="content-models.html#activation-behavior">activation behavior</a> depends on the
|
|
value of the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute
|
|
of the element, as follows:</p>
|
|
|
|
<dl class="switch"><dt>If the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is
|
|
in the <a href="#attr-command-type-state-checkbox" title="attr-command-type-state-checkbox">Checkbox</a> state</dt>
|
|
|
|
<dd><p>If the element has a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, the UA must
|
|
remove that attribute. Otherwise, the UA must add a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, with the
|
|
literal value <code title="">checked</code>. The UA must then
|
|
<a href="webappapis.html#fire-a-click-event">fire a <code title="event-click">click</code> event</a> at the
|
|
element.</p></dd>
|
|
|
|
|
|
<dt>If the <code title="attr-command-type"><a href="#attr-command-type">type</a></code> attribute is
|
|
in the <a href="#attr-command-type-state-radio" title="attr-command-type-state-radio">Radio</a> state</dt>
|
|
|
|
<dd><p>If the element has a parent, then the UA must walk the list
|
|
of child nodes of that parent element, and for each node that is a
|
|
<code><a href="#the-command-element">command</a></code> element, if that element has a <code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code> attribute whose
|
|
value exactly matches the current element's (treating missing <code title="attr-command-radiogroup"><a href="#attr-command-radiogroup">radiogroup</a></code> attributes as if
|
|
they were the empty string), and has a <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute, must remove
|
|
that attribute.</p>
|
|
|
|
<p>Then, the element's <code title="attr-command-checked"><a href="#attr-command-checked">checked</a></code> attribute attribute
|
|
must be set to the literal value <code title="">checked</code> and
|
|
the user agent must <a href="webappapis.html#fire-a-click-event">fire a <code title="event-click">click</code>
|
|
event</a> at the element.</p></dd>
|
|
|
|
|
|
<dt>Otherwise</dt>
|
|
|
|
<dd><p>The element has no <a href="content-models.html#activation-behavior">activation behavior</a>.</p></dd>
|
|
|
|
</dl><p class="note">Firing a synthetic <code title="event-click"><a href="infrastructure.html#event-click">click</a></code> event at the element does not cause
|
|
any of the actions described above to happen.</p>
|
|
|
|
|
|
</div><p class="note"><code><a href="#the-command-element">command</a></code> elements are not rendered
|
|
unless they <a href="#the-menu-element" title="menu">form part of a menu</a>.</p><div class="example">
|
|
|
|
<p>Here is an example of a toolbar with three buttons that let the
|
|
user toggle between left, center, and right alignment. One could
|
|
imagine such a toolbar as part of a text editor. The toolbar also
|
|
has a separator followed by another button labeled "Publish",
|
|
though that button is disabled.</p>
|
|
|
|
<pre><menu type="toolbar">
|
|
<command type="radio" radiogroup="alignment" checked="checked"
|
|
label="Left" icon="icons/alL.png" onclick="setAlign('left')">
|
|
<command type="radio" radiogroup="alignment"
|
|
label="Center" icon="icons/alC.png" onclick="setAlign('center')">
|
|
<command type="radio" radiogroup="alignment"
|
|
label="Right" icon="icons/alR.png" onclick="setAlign('right')">
|
|
<hr>
|
|
<command type="command" disabled
|
|
label="Publish" icon="icons/pub.png" onclick="publish()">
|
|
</menu></pre>
|
|
|
|
</div><h4 id="the-menu-element"><span class="secno">4.11.4 </span>The <dfn id="menus"><code>menu</code></dfn> element</h4><dl class="element"><dt>Categories</dt>
|
|
<dd><a href="content-models.html#flow-content">Flow content</a>.</dd>
|
|
<dd>If the element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state: <a href="content-models.html#interactive-content">Interactive content</a>.</dd>
|
|
<dt>Contexts in which this element can be used:</dt>
|
|
<dd>Where <a href="content-models.html#flow-content">flow content</a> is expected.</dd>
|
|
<dt>Content model:</dt>
|
|
<dd>Either: Zero or more <code><a href="grouping-content.html#the-li-element">li</a></code> elements.</dd>
|
|
<dd>Or: <a href="content-models.html#flow-content">Flow content</a>.</dd>
|
|
<dt>Content attributes:</dt>
|
|
<dd><a href="elements.html#global-attributes">Global attributes</a></dd>
|
|
<dd><code title="attr-menu-type"><a href="#attr-menu-type">type</a></code></dd>
|
|
<dd><code title="attr-menu-label"><a href="#attr-menu-label">label</a></code></dd>
|
|
<dt>DOM interface:</dt>
|
|
<dd>
|
|
<pre class="idl">interface <dfn id="htmlmenuelement">HTMLMenuElement</dfn> : <a href="elements.html#htmlelement">HTMLElement</a> {
|
|
attribute DOMString <a href="#dom-menu-type" title="dom-menu-type">type</a>;
|
|
attribute DOMString <a href="#dom-menu-label" title="dom-menu-label">label</a>;
|
|
};</pre>
|
|
</dd></dl><p>The <code><a href="#the-menu-element">menu</a></code> element represents a list of commands.</p><p>The <dfn id="attr-menu-type" title="attr-menu-type"><code>type</code></dfn> attribute
|
|
is an <a href="common-microsyntaxes.html#enumerated-attribute">enumerated attribute</a> indicating the kind of menu
|
|
being declared. The attribute has three states. The <code title="attr-menu-type-context">context</code> keyword maps to the
|
|
<dfn id="context-menu-state" title="context menu state">context menu</dfn> state, in which
|
|
the element is declaring a context menu. The <code title="attr-menu-type-toolbar">toolbar</code> keyword maps to the
|
|
<dfn id="toolbar-state" title="toolbar state">toolbar</dfn> state, in which the
|
|
element is declaring a toolbar. The attribute may also be
|
|
omitted. The <i>missing value default</i> is the <dfn id="list-state" title="list
|
|
state">list</dfn> state, which indicates that the element is merely
|
|
a list of commands that is neither declaring a context menu nor
|
|
defining a toolbar.</p><p>If a <code><a href="#the-menu-element">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#context-menu-state" title="context menu state">context menu</a> state, then the
|
|
element <a href="rendering.html#represents">represents</a> the commands of a context menu, and
|
|
the user can only interact with the commands if that context menu is
|
|
activated.</p><p>If a <code><a href="#the-menu-element">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state, then the element
|
|
<a href="rendering.html#represents">represents</a> a list of active commands that the user can
|
|
immediately interact with.</p><p>If a <code><a href="#the-menu-element">menu</a></code> element's <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute is in the <a href="#list-state" title="list state">list</a> state, then the element either
|
|
<a href="rendering.html#represents">represents</a> an unordered list of items (each represented
|
|
by an <code><a href="grouping-content.html#the-li-element">li</a></code> element), each of which represents a command
|
|
that the user can perform or activate, or, if the element has no
|
|
<code><a href="grouping-content.html#the-li-element">li</a></code> element children, <a href="content-models.html#flow-content">flow content</a>
|
|
describing available commands.</p><p>The <dfn id="attr-menu-label" title="attr-menu-label"><code>label</code></dfn>
|
|
attribute gives the label of the menu. It is used by user agents to
|
|
display nested menus in the UI. For example, a context menu
|
|
containing another menu would use the nested menu's <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute for the submenu's
|
|
menu label.</p><div class="impl">
|
|
|
|
<p>The <dfn id="dom-menu-type" title="dom-menu-type"><code>type</code></dfn> and <dfn id="dom-menu-label" title="dom-menu-label"><code>label</code></dfn> IDL attributes must
|
|
<a href="common-dom-interfaces.html#reflect">reflect</a> the respective content attributes of the same
|
|
name.</p>
|
|
|
|
</div><h5 id="menus-intro"><span class="secno">4.11.4.1 </span>Introduction</h5><p><i>This section is non-normative.</i></p><p>The <code><a href="#the-menu-element">menu</a></code> element is used to define context menus and
|
|
toolbars.</p><p>For example, the following represents a toolbar with three menu
|
|
buttons on it, each of which has a dropdown menu with a series of
|
|
options:</p><pre><menu type="toolbar">
|
|
<li>
|
|
<menu label="File">
|
|
<button type="button" onclick="fnew()">New...</button>
|
|
<button type="button" onclick="fopen()">Open...</button>
|
|
<button type="button" onclick="fsave()">Save</button>
|
|
<button type="button" onclick="fsaveas()">Save as...</button>
|
|
</menu>
|
|
</li>
|
|
<li>
|
|
<menu label="Edit">
|
|
<button type="button" onclick="ecopy()">Copy</button>
|
|
<button type="button" onclick="ecut()">Cut</button>
|
|
<button type="button" onclick="epaste()">Paste</button>
|
|
</menu>
|
|
</li>
|
|
<li>
|
|
<menu label="Help">
|
|
<li><a href="help.html">Help</a></li>
|
|
<li><a href="about.html">About</a></li>
|
|
</menu>
|
|
</li>
|
|
</menu></pre><p>In a supporting user agent, this might look like this:</p><p><img alt="A toolbar with three buttons, labeled 'File', 'Edit', and 'Help'; where if you select the 'Edit' button you get a drop-down menu with three more options, 'Copy', 'Cut', and 'Paste'." height="101" src="sample-toolbar-1.png" width="303"></p><p>In a legacy user agent, the above would look like a bulleted list
|
|
with three items, the first of which has four buttons, the second of
|
|
which has three, and the third of which has two nested bullet points
|
|
with two items consisting of links.</p><hr><p>The following implements a similar toolbar, with a single button
|
|
whose values, when selected, redirect the user to Web sites.</p><pre><form action="redirect.cgi">
|
|
<menu type="toolbar">
|
|
<label for="goto">Go to...</label>
|
|
<menu label="Go">
|
|
<select id="goto">
|
|
<option value="" selected="selected"> Select site: </option>
|
|
<option value="http://www.apple.com/"> Apple </option>
|
|
<option value="http://www.mozilla.org/"> Mozilla </option>
|
|
<option value="http://www.opera.com/"> Opera </option>
|
|
</select>
|
|
<span><input type="submit" value="Go"></span>
|
|
</menu>
|
|
</menu>
|
|
</form></pre><p>The behavior in supporting user agents is similar to the example
|
|
above, but here the legacy behavior consists of a single
|
|
<code><a href="the-button-element.html#the-select-element">select</a></code> element with a submit button. The submit button
|
|
doesn't appear in the toolbar, because it is not a direct child of
|
|
the <code><a href="#the-menu-element">menu</a></code> element or of its <code><a href="grouping-content.html#the-li-element">li</a></code>
|
|
children.</p><div class="impl">
|
|
|
|
<h5 id="building-menus-and-toolbars"><span class="secno">4.11.4.2 </span><dfn>Building menus and toolbars</dfn></h5>
|
|
|
|
<p>A menu (or toolbar) consists of a list of zero or more of the
|
|
following components:</p>
|
|
|
|
<ul class="brief"><li><a href="commands.html#concept-command" title="concept-command">Commands</a>, which can be marked as default commands</li>
|
|
<li>Separators</li>
|
|
<li>Other menus (which allows the list to be nested)</li>
|
|
</ul><p>The list corresponding to a particular <code><a href="#the-menu-element">menu</a></code> element
|
|
is built by iterating over its child nodes. For each child node in
|
|
<a href="infrastructure.html#tree-order">tree order</a>, the required behavior depends on what the
|
|
node is, as follows:</p>
|
|
|
|
<dl class="switch"><dt>An element that <a href="commands.html#concept-command" title="concept-command">defines a command</a></dt>
|
|
|
|
<dd>Append the command to the menu, respecting its <a href="commands.html#concept-facet" title="concept-facet">facets</a>. </dd>
|
|
|
|
|
|
<dt>An <code><a href="grouping-content.html#the-hr-element">hr</a></code> element</dt>
|
|
<dt>An <code><a href="the-button-element.html#the-option-element">option</a></code> element that has a <code title="attr-option-value"><a href="the-button-element.html#attr-option-value">value</a></code> attribute set to the empty
|
|
string, and has a <code title="attr-option-disabled"><a href="the-button-element.html#attr-option-disabled">disabled</a></code> attribute, and whose
|
|
<code><a href="infrastructure.html#textcontent">textContent</a></code> consists of a string of one or more
|
|
hyphens (U+002D HYPHEN-MINUS)</dt>
|
|
|
|
<dd>Append a separator to the menu.</dd>
|
|
|
|
|
|
<dt>An <code><a href="grouping-content.html#the-li-element">li</a></code> element</dt>
|
|
<dt>A <code><a href="forms.html#the-label-element">label</a></code> element</dt>
|
|
|
|
<dd>Iterate over the children of the element.</dd>
|
|
|
|
|
|
<dt>A <code><a href="#the-menu-element">menu</a></code> element with no <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
|
|
<dt>A <code><a href="the-button-element.html#the-select-element">select</a></code> element</dt>
|
|
|
|
<dd>Append a separator to the menu, then iterate over the children
|
|
of the <code><a href="#the-menu-element">menu</a></code> or <code><a href="the-button-element.html#the-select-element">select</a></code> element, then
|
|
append another separator.</dd>
|
|
|
|
|
|
|
|
|
|
<dt>A <code><a href="#the-menu-element">menu</a></code> element with a <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
|
|
<dt>An <code><a href="the-button-element.html#the-optgroup-element">optgroup</a></code> element with a <code title="attr-menu-label"><a href="#attr-menu-label">label</a></code> attribute</dt>
|
|
|
|
<dd>Append a submenu to the menu, using the value of the element's
|
|
<code title="">label</code> attribute as the label of the menu. The
|
|
submenu must be constructed by taking the element and creating a
|
|
new menu for it using the complete process described in this
|
|
section.</dd>
|
|
|
|
|
|
<dt>Any other node</dt>
|
|
|
|
<dd><a href="infrastructure.html#ignore">Ignore</a> the node.</dd>
|
|
|
|
</dl><p>Once all the nodes have been processed as described above, the
|
|
user agent must the post-process the menu as follows:</p>
|
|
|
|
<ol><li>Except for separators, any menu item with no label, or whose
|
|
label is the empty string, must be removed.</li>
|
|
|
|
<li>Any sequence of two or more separators in a row must be
|
|
collapsed to a single separator.</li>
|
|
|
|
<li>Any separator at the start or end of the menu must be
|
|
removed.</li>
|
|
|
|
</ol></div><h5 id="context-menus"><span class="secno">4.11.4.3 </span><dfn>Context menus</dfn></h5><p>The <dfn id="attr-contextmenu" title="attr-contextmenu"><code>contextmenu</code></dfn>
|
|
attribute gives the element's <a href="#context-menus" title="context menus">context
|
|
menu</a>. The value must be the <a href="elements.html#concept-id" title="concept-id">ID</a> of a <code><a href="#the-menu-element">menu</a></code> element
|
|
in the DOM. <span class="impl">If the node that would be obtained by
|
|
the invoking the <code title="dom-Document-getElementById"><a href="infrastructure.html#dom-document-getelementbyid">getElementById()</a></code> method
|
|
using the attribute's value as the only argument is null or not a
|
|
<code><a href="#the-menu-element">menu</a></code> element, then the element has no assigned context
|
|
menu. Otherwise, the element's assigned context menu is the element
|
|
so identified.</span></p><div class="impl">
|
|
|
|
<p>When an element's context menu is requested (e.g. by the user
|
|
right-clicking the element, or pressing a context menu key), the
|
|
user agent must apply the appropriate rules from the following
|
|
list:</p>
|
|
|
|
<dl class="switch"><dt>If the user requested a context menu using a pointing device</dt>
|
|
|
|
<dd><p>The user agent must dispatch an event with the name <code title="event-contextmenu">contextmenu</code>, that bubbles and is
|
|
cancelable, and that uses the <code><a href="infrastructure.html#mouseevent">MouseEvent</a></code> interface, at
|
|
the element for which the menu was requested. The context
|
|
information of the event must be set to the same values as the last
|
|
<code><a href="infrastructure.html#mouseevent">MouseEvent</a></code> user interaction event that was dispatched
|
|
as part of the gesture that that was interpreted as a request for
|
|
the context menu.</p></dd>
|
|
|
|
<dt>Otherwise</dt>
|
|
|
|
<dd><p>The user agent must <a href="webappapis.html#fire-a-synthetic-mouse-event" title="fire a synthetic mouse
|
|
event">fire a synthetic mouse event named <code title="event-contextmenu">contextmenu</code></a> that bubbles
|
|
and is cancelable at the element for which the menu was
|
|
requested.</p></dd>
|
|
|
|
</dl><p class="note">Typically, therefore, the firing of the <code title="event-contextmenu">contextmenu</code> event will be the
|
|
default action of a <code title="mouseup">mouseup</code> or <code title="event-keyup">keyup</code> event. The exact sequence of events
|
|
is UA-dependent, as it will vary based on platform conventions.</p>
|
|
|
|
<p>The default action of the <code title="event-contextmenu">contextmenu</code> event depends on
|
|
whether the element or one of its ancestors has a context menu
|
|
assigned (using the <code title="attr-contextmenu"><a href="#attr-contextmenu">contextmenu</a></code> attribute) or not. If
|
|
there is no context menu assigned, the default action must be for
|
|
the user agent to show its default context menu, if it has one.</p>
|
|
|
|
<p>If the element or one of its ancestors <em>does</em> have a
|
|
context menu assigned, then the user agent must <a href="webappapis.html#fire-a-simple-event">fire a simple
|
|
event</a> named <code title="event-show">show</code> at the
|
|
<code><a href="#the-menu-element">menu</a></code> element of the context menu of the nearest
|
|
ancestor (including the element itself) with one assigned.</p>
|
|
|
|
|
|
<p>The default action of <em>this</em> event is that the user agent
|
|
must show a context menu <a href="#building-menus-and-toolbars" title="building menus and
|
|
toolbars">built</a> from the <code><a href="#the-menu-element">menu</a></code> element.</p>
|
|
|
|
<p>The user agent may also provide access to its default context
|
|
menu, if any, with the context menu shown. For example, it could
|
|
merge the menu items from the two menus together, or provide the
|
|
page's context menu as a submenu of the default menu.</p>
|
|
|
|
<p>If the user dismisses the menu without making a selection,
|
|
nothing in particular happens.</p>
|
|
|
|
<p>If the user selects a menu item that represents a <a href="commands.html#concept-command" title="concept-command">command</a>, then the UA must invoke
|
|
that command's <a href="commands.html#command-facet-action" title="command-facet-Action">Action</a>.</p>
|
|
|
|
<p>Context menus must not, while being shown, reflect changes in the
|
|
DOM; they are constructed as the default action of the <code title="event-show">show</code> event and must remain as constructed
|
|
until dismissed.</p>
|
|
|
|
<p>User agents may provide means for bypassing the context menu
|
|
processing model, ensuring that the user can always access the UA's
|
|
default context menus. For example, the user agent could handle
|
|
right-clicks that have the Shift key depressed in such a way that it
|
|
does not fire the <code title="event-contextmenu">contextmenu</code>
|
|
event and instead always shows the default context menu.</p>
|
|
|
|
<p>The <dfn id="dom-contextmenu" title="dom-contextMenu"><code>contextMenu</code></dfn>
|
|
IDL attribute must <a href="common-dom-interfaces.html#reflect">reflect</a> the <code title="attr-contextmenu"><a href="#attr-contextmenu">contextmenu</a></code> content attribute.</p>
|
|
|
|
</div><div class="example">
|
|
|
|
<p>Here is an example of a context menu for an input control:</p>
|
|
|
|
<pre><form name="npc">
|
|
<label>Character name: <input name=char type=text contextmenu=namemenu required></label>
|
|
<menu type=context id=namemenu>
|
|
<command label="Pick random name" onclick="document.forms.npc.elements.char.value = getRandomName()">
|
|
<command label="Prefill other fields based on name" onclick="prefillFields(document.forms.npc.elements.char.value)">
|
|
</menu>
|
|
</form></pre>
|
|
|
|
<p>This adds two items to the control's context menu, one called
|
|
"Pick random name", and one called "Prefill other fields based on
|
|
name". They invoke scripts that are not shown in the example
|
|
above.</p>
|
|
|
|
</div><div class="impl">
|
|
|
|
<h5 id="toolbars"><span class="secno">4.11.4.4 </span><dfn>Toolbars</dfn></h5>
|
|
|
|
<p>When a <code><a href="#the-menu-element">menu</a></code> element has a <code title="attr-menu-type"><a href="#attr-menu-type">type</a></code> attribute in the <a href="#toolbar-state" title="toolbar state">toolbar</a> state, then the user agent
|
|
must <a href="#building-menus-and-toolbars" title="building menus and toolbars">build</a> the
|
|
menu for that <code><a href="#the-menu-element">menu</a></code> element, and use the result in the
|
|
rendering.</p>
|
|
|
|
<p>The user agent must reflect changes made to the
|
|
<code><a href="#the-menu-element">menu</a></code>'s DOM, by immediately <a href="#building-menus-and-toolbars" title="building menus
|
|
and toolbars">rebuilding</a> the menu.</p>
|
|
|
|
</div></body></html>
|