1.仕様
MENUITEM要素は、
操作項目を
表します。
- menuitem
-
メニュー項目 (menu item)
HTML5.1 で追加, HTML5.2 で廃止の要素です。
- 種類
-
空要素
任意のコンテンツを持つことができない要素です。
- カテゴリ
-
なし
- 使用できるコンテキスト
-
menu
要素 に 0個以上menu
要素 に 0個以上を そのコンテンツとして、使用できます。 - コンテンツモデル
-
何もない
要素のコンテンツモデルが「何もない」の場合、要素にはテキストノード (要素間の空白以外) と要素ノードが含まれていてはなりません。
- タグの省略
-
終了タグはありません。
- コンテンツ属性
-
グローバル属性 他
- type
属性 - コマンドの種類
- label
属性 - ユーザーに見えるラベル
- icon
属性 - コマンドのアイコン
- disabled
属性 - コマンドまたはコントロールが無効かどうか
- checked
属性 - コマンドまたはコントロールがチェックされているかどうか
- radiogroup
属性 - ラジオボタングループとして扱うコマンドのグループ名
- default
属性 - コマンドをデフォルトコマンドとしてマークする
- title
属性 - コマンドを説明するヒント
- type
- DOM インターフェイス
-
HTMLMenuItemElement
[Exposed=Window]
interface HTMLMenuItemElement : HTMLElement {
[HTMLConstructor] constructor();
[CEReactions] attribute DOMString type;
[CEReactions] attribute DOMString label;
[CEReactions] attribute DOMString icon;
[CEReactions] attribute boolean disabled;
[CEReactions] attribute boolean checked;
[CEReactions] attribute DOMString radiogroup;
[CEReactions] attribute boolean boolean default;
};
HTMLElement
[Exposed=Window]
interface HTMLElement : Element {
[HTMLConstructor] constructor();
// metadata attributes
[CEReactions] attribute DOMString title;
[CEReactions] attribute DOMString lang;
[CEReactions] attribute boolean translate;
[CEReactions] attribute DOMString dir;
// user interaction
[CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
[CEReactions] attribute DOMString inert;
undefined click();
[CEReactions] attribute DOMString accessKey;
readonly attribute DOMString accessKeyLabel;
[CEReactions] attribute boolean draggable;
[CEReactions] attribute boolean spellcheck;
[CEReactions] attribute DOMString writingSuggestions;
[CEReactions] attribute DOMString autocapitalize;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
[CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
ElementInternals attachInternals();
// The popover API
undefined showPopover();
undefined hidePopover();
boolean togglePopover(optional boolean force);
[CEReactions] attribute DOMString? popover;
};
HTMLElement includes GlobalEventHandlers;
HTMLElement includes ElementContentEditable;
HTMLElement includes HTMLOrSVGElement;
Element
[Exposed=Window]
interface Element : Node {
readonly attribute DOMString? namespaceURI;
readonly attribute DOMString? prefix;
readonly attribute DOMString localName;
readonly attribute DOMString tagName;
[CEReactions] attribute DOMString id;
[CEReactions] attribute DOMString className;
[SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
[CEReactions, Unscopable] attribute DOMString slot;
boolean hasAttributes();
[SameObject] readonly attribute NamedNodeMap attributes;
sequence<DOMString> getAttributeNames();
DOMString? getAttribute(DOMString qualifiedName);
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
boolean hasAttribute(DOMString qualifiedName);
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
Attr? getAttributeNode(DOMString qualifiedName);
Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
[CEReactions] Attr? setAttributeNode(Attr attr);
[CEReactions] Attr? setAttributeNodeNS(Attr attr);
[CEReactions] Attr removeAttributeNode(Attr attr);
ShadowRoot attachShadow(ShadowRootInit init);
readonly attribute ShadowRoot? shadowRoot;
Element? closest(DOMString selectors);
boolean matches(DOMString selectors);
boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
HTMLCollection getElementsByTagName(DOMString qualifiedName);
HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
HTMLCollection getElementsByClassName(DOMString classNames);
[CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
undefined insertAdjacentText(DOMString where, DOMString data); // legacy
};
GlobalEventHandlers
interface mixin GlobalEventHandlers {
attribute EventHandler onabort;
attribute EventHandler onauxclick;
attribute EventHandler onbeforeinput;
attribute EventHandler onbeforematch;
attribute EventHandler onbeforetoggle;
attribute EventHandler onblur;
attribute EventHandler oncancel;
attribute EventHandler oncanplay;
attribute EventHandler oncanplaythrough;
attribute EventHandler onchange;
attribute EventHandler onclick;
attribute EventHandler onclose;
attribute EventHandler oncontextlost;
attribute EventHandler oncontextmenu;
attribute EventHandler oncontextrestored;
attribute EventHandler oncopy;
attribute EventHandler oncuechange;
attribute EventHandler oncut;
attribute EventHandler ondblclick;
attribute EventHandler ondrag;
attribute EventHandler ondragend;
attribute EventHandler ondragenter;
attribute EventHandler ondragleave;
attribute EventHandler ondragover;
attribute EventHandler ondragstart;
attribute EventHandler ondrop;
attribute EventHandler ondurationchange;
attribute EventHandler onemptied;
attribute EventHandler onended;
attribute OnErrorEventHandler onerror;
attribute EventHandler onfocus;
attribute EventHandler onformdata;
attribute EventHandler oninput;
attribute EventHandler oninvalid;
attribute EventHandler onkeydown;
attribute EventHandler onkeypress;
attribute EventHandler onkeyup;
attribute EventHandler onload;
attribute EventHandler onloadeddata;
attribute EventHandler onloadedmetadata;
attribute EventHandler onloadstart;
attribute EventHandler onmousedown;
[LegacyLenientThis] attribute EventHandler onmouseenter;
[LegacyLenientThis] attribute EventHandler onmouseleave;
attribute EventHandler onmousemove;
attribute EventHandler onmouseout;
attribute EventHandler onmouseover;
attribute EventHandler onmouseup;
attribute EventHandler onpaste;
attribute EventHandler onpause;
attribute EventHandler onplay;
attribute EventHandler onplaying;
attribute EventHandler onprogress;
attribute EventHandler onratechange;
attribute EventHandler onreset;
attribute EventHandler onresize;
attribute EventHandler onscroll;
attribute EventHandler onscrollend;
attribute EventHandler onsecuritypolicyviolation;
attribute EventHandler onseeked;
attribute EventHandler onseeking;
attribute EventHandler onselect;
attribute EventHandler onslotchange;
attribute EventHandler onstalled;
attribute EventHandler onsubmit;
attribute EventHandler onsuspend;
attribute EventHandler ontimeupdate;
attribute EventHandler ontoggle;
attribute EventHandler onvolumechange;
attribute EventHandler onwaiting;
attribute EventHandler onwebkitanimationend;
attribute EventHandler onwebkitanimationiteration;
attribute EventHandler onwebkitanimationstart;
attribute EventHandler onwebkittransitionend;
attribute EventHandler onwheel;
};
ElementContentEditable
interface mixin ElementContentEditable {
[CEReactions] attribute DOMString contentEditable;
[CEReactions] attribute DOMString enterKeyHint;
readonly attribute boolean isContentEditable;
[CEReactions] attribute DOMString inputMode;
};
HTMLOrSVGElement
interface mixin HTMLOrSVGElement {
[SameObject] readonly attribute DOMStringMap dataset;
attribute DOMString nonce; // intentionally no [CEReactions]
[CEReactions] attribute boolean autofocus;
[CEReactions] attribute long tabIndex;
undefined focus(optional FocusOptions options = {});
undefined blur();
};
- ARIA in HTML
-
暗黙的="
menuitem
" ARIAロール="No
" aria-* 属性="GlobalAny
"暗黙的な ARIAセマンティクスは、
role=menuitem
です。作成者は、暗黙的な ARIAセマンティクス, または HTML要素のネイティブセマンティクスを上書きしてはいけません。
グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。
- レンダリング
- ブロック
ボックス リスト
menuitem {
display: list-item;
text-align: match-parent;
unicode-bidi: isolate;
}
menuitem[type=checkbox i], menuitem[type=radio i] { display: inline-block; }
CSS を大雑把に読むと、 ブロックレベルのブロックコンテナボックス(ブロックボックス)を生成します。(マーカーの分のコンテナボックスも生成します。) などになります。
- 説明
-
menuitem
要素 は、ユーザーがポップアップメニュー (コンテキストメニュー) から呼び出すことができるコマンドを表します。menuitem
要素 は、ユーザーがポップアップメニュー(コンテキストメニュー)から呼び出すことができるコマンドを表します。
type, label, icon, disabled, checked, radiogroupの一つ以上を使うmenuitem要素は、新しいコマンドを定義します。
HTML5.1 で提案されただけで、HTML Living Standard で採用されておらず、対応しているブラウザもはないと思います。<!DOCTYPE html>
<html lang=
"ja"> <head>
<meta charset=
"utf-8"> <title>menuitem要素の例 - (Example of menuitem element) | 離珠のHTMLでしぃ!</title>
</head>
<body>
<h1>menuitem要素の例</h1>
<img src=
"../Img/G01/cafeboard_106l.gif" alt= "Cafe board" contextmenu= "imiCmmenu"> <menu type=
"context" id= "imiCmmenu"> <menuitem label=
"Pet the kittens" onclick= "kittens.pet()"> <menuitem label=
"Cuddle with the kittens" onclick= "kittens.cuddle()"> <menu label=
"Feed the kittens"> <menuitem label=
"Fish" onclick= "kittens.feed(fish)"> <menuitem label=
"Chicken" onclick= "kittens.feed(chicken)"> </menu>
</menu>
<p>HTML5.1 にある例示されているソースコードを用いた提示です。
対応しているブラウザーはないと思うのですが、一応の提示です。</p><p>提示するにあたり、画像とかIDとかは、あえて変えています。</p>
<a style=
"word-break: break-all" href= "https://www.w3.org/TR/2016/REC-html51-20161101/interactive-elements.html#example-e5c085bb" target= "_top">https://www.w3.org/TR/2016/REC-html51-20161101/interactive-elements.html#example-e5c085bb</a> </body>
</html>
このサンプルへのリンクです。
(./exmenuitem.htm) - 参照元
-
参照元
- HTML Living Standard. 16.2 Non-conforming features (Last Updated 27 August 2024)
- HTML 5.1 W3C 勧告. 4.11.4. The menuitem element (W3C勧告、2016年11月1日)
- <menuitem> - HTML: ハイパーテキストマークアップ言語 | MDN
- JSONデータ
-
JSON形式での、データのイメージです。
{
"menuitem": {
"check": "2024-09-01",
"group": "List",
"element": "- X EMPTY -- menu item. (Void elements.) [None] --",
"attlist": {
"%Global;": "",
"type": "CDATA #IMPLIED -- Type of command --",
"label": "CDATA #IMPLIED -- User-visible label --",
"icon": "CDATA #IMPLIED -- Icon for the command --",
"disabled": "(disabled) #IMPLIED -- Whether the command or control is disabled --",
"checked": "(checked) #IMPLIED -- Whether the command or control is checked --",
"radiogroup": "CDATA #IMPLIED -- Name of group of commands to treat as a radio button group --",
"default": "(default) #IMPLIED -- Mark the command as being a default command --",
},
"comment": "メニュー項目 (menu item)",
"point": "ユーザーがポップアップメニュー (コンテキストメニュー) から呼び出すことができるコマンドを表します。",
"description": [
"ユーザーがポップアップメニュー(コンテキストメニュー)から呼び出すことができるコマンドを表します。",
"type, label, icon, disabled, checked, radiogroupの一つ以上を使うmenuitem要素は、新しいコマンドを定義します。",
"HTML5.1 で提案されただけで、HTML Living Standard で採用されておらず、対応しているブラウザもはないと思います。",
],
"kind": "Void",
"categories": "None",
"used": "menu (menuitem)*",
"contentmodel": "%Nothing",
"tag": [
"-",
"X",
],
"attributes": {
"type": "コマンドの種類",
"label": "ユーザーに見えるラベル",
"icon": "コマンドのアイコン",
"disabled": "コマンドまたはコントロールが無効かどうか",
"checked": "コマンドまたはコントロールがチェックされているかどうか",
"radiogroup": "ラジオボタングループとして扱うコマンドのグループ名",
"default": "コマンドをデフォルトコマンドとしてマークする",
"title": "コマンドを説明するヒント",
},
"dominterface": "HTMLMenuItemElement",
"rendering": [
"Lists",
"Bidirectional",
],
"reference": [
{
"title": "HTML Living Standard. 16.2 Non-conforming features.",
"href": "https://html.spec.whatwg.org/multipage/obsolete.html#non-conforming-features",
"heading": "HTML Living Standard. 16.2 Non-conforming features",
"sub": "Last Updated 27 August 2024",
},
{
"title": "HTML 5.1 W3C Recommendation. 4.11.4. The menuitem element. W3C Recommendation, 1 November 2016.",
"href": "https://www.w3.org/TR/2016/REC-html51-20161101/interactive-elements.html#the-menuitem-element",
"heading": "HTML 5.1 W3C 勧告. 4.11.4. The menuitem element",
"sub": "W3C勧告、2016年11月1日",
},
{
"title": "MDN Web Docs. HTML <menuitem>",
"href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/menuitem",
"heading": "<menuitem> - HTML: ハイパーテキストマークアップ言語 | MDN",
},
],
"version": {
"first": "HTML5.1",
"latest": "HTML5.1",
},
}
}
注意: 簡易に描画する為に、各項目の後ろに
,
を付与しています。JSON の形式では、末尾の項目の後には,
は付けません。 - 最終確認日
-
2024-09-01
2.使用可能な箇所
menu要素 に
配置できます。
menu要素に配置できます。
3.配置できるコンテンツ
配置可能なコンテンツは
ありません。
menuitem
menuitem
4.属性
グローバル属性と、
type,
label,
icon,
disabled,
checked,
radiogroup,
default を
設定できます。
menuitemは、グローバル属性とtype属性, label属性, icon属性, disabled属性, checked属性, radiogroup属性, default属性 を設定できます。
また、グローバル属性である title属性ですが、この要素では特別な意味を持ちます。
<img src=
"../Img/G01/cafeboard_106l.gif" alt= "Cafe board" contextmenu= "imiCm400"> <menu type=
"context" id= "imiCm400"> <menuitem label=
"sample01" onclick= "alert('さんぷる1')"> </menu>
この雛型の 3 行目のmenuitem
例示は、ただソースコードをそのまま記述しただけであり、menuitem
例示では空要素のmenuitem

type属性
<menuitem type=
"command" label="sample01" onclick= "alert('さんぷる1')">
type
typeは、次のキーワード(keywords)と状態(states)を持つ列挙属性(enumerated attribute)です。
- command
- この要素は、関連するアクションを持つ通常のコマンドを表す。
- checkbox
- この要素は、トグルできる状態やオプションを表します。
- radio
- この要素は、アイテムのリストから1つのアイテムを選択することを表します。
列挙属性と呼ばれる一部の属性は、有限の状態セットを取ります。このような属性の状態は、属性の値、各属性の仕様で指定されたキーワード/状態マッピングのセット、および属性の仕様で指定できる 2 つの特殊な状態を組み合わせることによって生成されます。これらの特殊な状態は、無効な値のデフォルトと欠落した値のデフォルトです。
この属性の欠落値のデフォルトは command の状態です。

label属性
<menuitem type=
"command" label= "sample01" onclick="alert('さんぷる1')">
label

icon属性
<menuitem type=
"command" icon= "../Img/G01/hatena01k.gif" onclick="alert('さんぷる1')">
icon

disabled属性
<menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')" disabled>
disabled

checked属性
<menuitem type=
"checkbox" label= "checkbox01" checked> <menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')">
checked

radiogroup属性
<menuitem type=
"radio" label= "radio01" radiogroup= "group01" ><menuitem type=
"radio" label= "radio02" radiogroup= "group01" ><menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')">
radiogroup

default属性
<menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')" default>
default
使い方が良くわかりません。
title属性
<menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')" title= "これはソースコードの例示です。" >
title

5.Web API
menuitem要素を
直接表す
プロパティは
ありません。
menuitemを表すプロパティはないので、documentのquerySelectorAll()メソッドで条件を絞って、要素のリストを取得する方法があります。この時に取得できるのはHTMLMenuItemElement オブジェクトのリストです。例では属性menu[id="imiCm500"] > menuitem
と指定して、menuitemのリストを取得しています。documentのgetElementById()メソッドでmenuを取得してから、そのElementのquerySelectorAll()メソッドを用いるとか、状況, 目的によりいろいろあります。

この例示のmenuitemは、
"〇〇
"です。
<img src=
"../Img/G01/cafeboard_106l.gif" alt= "Cafe board" contextmenu= "imiCm500"> <menu type=
"context" id= "imiCm500"> <menuitem type=
"radio" label= "radio01" radiogroup= "group01"> </menuitem> <menuitem type=
"radio" label= "radio02" radiogroup= "group01"> </menuitem> <menuitem type=
"command" label= "sample01" onclick= "alert('さんぷる1')"> </menuitem> </menu>
<p>このページの説明は、
"<code id=
"JHSAMPLE051">〇〇</code>"です。</p> <script>
document
.addEventListener( "DOMContentLoaded", function() { var vaMenuitem = document
.querySelectorAll( "menu[id='imiCm500'] > menuitem"); var vaText = '';
for (var i = 0; i < vaMenuitem.length; i++){
vsText = vsText + vaMenuitem[i].getAttribute(
"label") + ' '; }
if (vsText) {
document
.getElementById( "JHSAMPLE051") .textContent = vsText; }
});
</script>
menuitemの一覧から、labelの値を取得する例です。
6.レンダリング
menuitem {
display: list-item;
unicode-bidi: isolate;
}
menuitem[type=checkbox i],
menuitem[type=radio i] {
display: inline-block;
}
menuitem
ブロック
unicode-bidi
は、置換されない要素のレンダリングでの Bidirectional text(双方向テキスト) に於いての期待される仕様の様です。
type
※ menuitem
7.気を付ける点
現行では、
ほとんど未対応の
要素です。
menuitemは、HTML5.1 で提案されましたが、HTML5.2 で廃止され、ほとんど対応したブラウザなどがありません。また、contextmenu
よって、カスタムコンテキストメニューを実装するには、この要素, 属性はないものとして、Elementのcontextmenuイベントを処理するスクリプトを使用します。