メインコンテンツへスキップ

menuitem要素


1.仕様

MENUITEM要素は、
操作項目を
表します。

menuitem

メニュー項目 (menu item)

HTML5.1 で追加, HTML5.2 で廃止の要素です。

種類
空要素

任意のコンテンツを持つことができない要素です。

カテゴリ

なし

使用できるコンテキスト
menu要素に 0個以上

menu要素に 0個以上を そのコンテンツとして、使用できます。

コンテンツモデル
何もない

要素のコンテンツモデルが「何もない」の場合、要素にはテキストノード (要素間の空白以外) と要素ノードが含まれていてはなりません。

タグの省略

終了タグはありません。

コンテンツ属性
グローバル属性 他
type属性
コマンドの種類
label属性
ユーザーに見えるラベル
icon属性
コマンドのアイコン
disabled属性
コマンドまたはコントロールが無効かどうか
checked属性
コマンドまたはコントロールがチェックされているかどうか
radiogroup属性
ラジオボタングループとして扱うコマンドのグループ名
default属性
コマンドをデフォルトコマンドとしてマークする
title属性
コマンドを説明するヒント
DOM インターフェイス
HTMLMenuItemElement
  1. [Exposed=Window]
  2. interface HTMLMenuItemElement : HTMLElement {
  3. [HTMLConstructor] constructor();
  4.  
  5. [CEReactions] attribute DOMString type;
  6. [CEReactions] attribute DOMString label;
  7. [CEReactions] attribute DOMString icon;
  8. [CEReactions] attribute boolean disabled;
  9. [CEReactions] attribute boolean checked;
  10. [CEReactions] attribute DOMString radiogroup;
  11. [CEReactions] attribute boolean boolean default;
  12. };
HTMLElement
  1. [Exposed=Window]
  2. interface HTMLElement : Element {
  3. [HTMLConstructor] constructor();
  4.  
  5. // metadata attributes
  6. [CEReactions] attribute DOMString title;
  7. [CEReactions] attribute DOMString lang;
  8. [CEReactions] attribute boolean translate;
  9. [CEReactions] attribute DOMString dir;
  10.  
  11. // user interaction
  12. [CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
  13. [CEReactions] attribute DOMString inert;
  14. undefined click();
  15. [CEReactions] attribute DOMString accessKey;
  16. readonly attribute DOMString accessKeyLabel;
  17. [CEReactions] attribute boolean draggable;
  18. [CEReactions] attribute boolean spellcheck;
  19. [CEReactions] attribute DOMString writingSuggestions;
  20. [CEReactions] attribute DOMString autocapitalize;
  21.  
  22. [CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
  23. [CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
  24.  
  25. ElementInternals attachInternals();
  26.  
  27. // The popover API
  28. undefined showPopover();
  29. undefined hidePopover();
  30. boolean togglePopover(optional boolean force);
  31. [CEReactions] attribute DOMString? popover;
  32. };
  33.  
  34. HTMLElement includes GlobalEventHandlers;
  35. HTMLElement includes ElementContentEditable;
  36. HTMLElement includes HTMLOrSVGElement;
Element
  1. [Exposed=Window]
  2. interface Element : Node {
  3. readonly attribute DOMString? namespaceURI;
  4. readonly attribute DOMString? prefix;
  5. readonly attribute DOMString localName;
  6. readonly attribute DOMString tagName;
  7.  
  8. [CEReactions] attribute DOMString id;
  9. [CEReactions] attribute DOMString className;
  10. [SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
  11. [CEReactions, Unscopable] attribute DOMString slot;
  12.  
  13. boolean hasAttributes();
  14. [SameObject] readonly attribute NamedNodeMap attributes;
  15. sequence<DOMString> getAttributeNames();
  16. DOMString? getAttribute(DOMString qualifiedName);
  17. DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
  18. [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
  19. [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
  20. [CEReactions] undefined removeAttribute(DOMString qualifiedName);
  21. [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
  22. [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
  23. boolean hasAttribute(DOMString qualifiedName);
  24. boolean hasAttributeNS(DOMString? namespace, DOMString localName);
  25.  
  26. Attr? getAttributeNode(DOMString qualifiedName);
  27. Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
  28. [CEReactions] Attr? setAttributeNode(Attr attr);
  29. [CEReactions] Attr? setAttributeNodeNS(Attr attr);
  30. [CEReactions] Attr removeAttributeNode(Attr attr);
  31.  
  32. ShadowRoot attachShadow(ShadowRootInit init);
  33. readonly attribute ShadowRoot? shadowRoot;
  34.  
  35. Element? closest(DOMString selectors);
  36. boolean matches(DOMString selectors);
  37. boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
  38.  
  39. HTMLCollection getElementsByTagName(DOMString qualifiedName);
  40. HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
  41. HTMLCollection getElementsByClassName(DOMString classNames);
  42.  
  43. [CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
  44. undefined insertAdjacentText(DOMString where, DOMString data); // legacy
  45. };
GlobalEventHandlers
  1. interface mixin GlobalEventHandlers {
  2. attribute EventHandler onabort;
  3. attribute EventHandler onauxclick;
  4. attribute EventHandler onbeforeinput;
  5. attribute EventHandler onbeforematch;
  6. attribute EventHandler onbeforetoggle;
  7. attribute EventHandler onblur;
  8. attribute EventHandler oncancel;
  9. attribute EventHandler oncanplay;
  10. attribute EventHandler oncanplaythrough;
  11. attribute EventHandler onchange;
  12. attribute EventHandler onclick;
  13. attribute EventHandler onclose;
  14. attribute EventHandler oncontextlost;
  15. attribute EventHandler oncontextmenu;
  16. attribute EventHandler oncontextrestored;
  17. attribute EventHandler oncopy;
  18. attribute EventHandler oncuechange;
  19. attribute EventHandler oncut;
  20. attribute EventHandler ondblclick;
  21. attribute EventHandler ondrag;
  22. attribute EventHandler ondragend;
  23. attribute EventHandler ondragenter;
  24. attribute EventHandler ondragleave;
  25. attribute EventHandler ondragover;
  26. attribute EventHandler ondragstart;
  27. attribute EventHandler ondrop;
  28. attribute EventHandler ondurationchange;
  29. attribute EventHandler onemptied;
  30. attribute EventHandler onended;
  31. attribute OnErrorEventHandler onerror;
  32. attribute EventHandler onfocus;
  33. attribute EventHandler onformdata;
  34. attribute EventHandler oninput;
  35. attribute EventHandler oninvalid;
  36. attribute EventHandler onkeydown;
  37. attribute EventHandler onkeypress;
  38. attribute EventHandler onkeyup;
  39. attribute EventHandler onload;
  40. attribute EventHandler onloadeddata;
  41. attribute EventHandler onloadedmetadata;
  42. attribute EventHandler onloadstart;
  43. attribute EventHandler onmousedown;
  44. [LegacyLenientThis] attribute EventHandler onmouseenter;
  45. [LegacyLenientThis] attribute EventHandler onmouseleave;
  46. attribute EventHandler onmousemove;
  47. attribute EventHandler onmouseout;
  48. attribute EventHandler onmouseover;
  49. attribute EventHandler onmouseup;
  50. attribute EventHandler onpaste;
  51. attribute EventHandler onpause;
  52. attribute EventHandler onplay;
  53. attribute EventHandler onplaying;
  54. attribute EventHandler onprogress;
  55. attribute EventHandler onratechange;
  56. attribute EventHandler onreset;
  57. attribute EventHandler onresize;
  58. attribute EventHandler onscroll;
  59. attribute EventHandler onscrollend;
  60. attribute EventHandler onsecuritypolicyviolation;
  61. attribute EventHandler onseeked;
  62. attribute EventHandler onseeking;
  63. attribute EventHandler onselect;
  64. attribute EventHandler onslotchange;
  65. attribute EventHandler onstalled;
  66. attribute EventHandler onsubmit;
  67. attribute EventHandler onsuspend;
  68. attribute EventHandler ontimeupdate;
  69. attribute EventHandler ontoggle;
  70. attribute EventHandler onvolumechange;
  71. attribute EventHandler onwaiting;
  72. attribute EventHandler onwebkitanimationend;
  73. attribute EventHandler onwebkitanimationiteration;
  74. attribute EventHandler onwebkitanimationstart;
  75. attribute EventHandler onwebkittransitionend;
  76. attribute EventHandler onwheel;
  77. };
ElementContentEditable
  1. interface mixin ElementContentEditable {
  2. [CEReactions] attribute DOMString contentEditable;
  3. [CEReactions] attribute DOMString enterKeyHint;
  4. readonly attribute boolean isContentEditable;
  5. [CEReactions] attribute DOMString inputMode;
  6. };
HTMLOrSVGElement
  1. interface mixin HTMLOrSVGElement {
  2. [SameObject] readonly attribute DOMStringMap dataset;
  3. attribute DOMString nonce; // intentionally no [CEReactions]
  4.  
  5. [CEReactions] attribute boolean autofocus;
  6. [CEReactions] attribute long tabIndex;
  7. undefined focus(optional FocusOptions options = {});
  8. undefined blur();
  9. };
ARIA in HTML
暗黙的="menuitem" ARIAロール="No" aria-* 属性="GlobalAny"

暗黙的な ARIAセマンティクスは、role=menuitem です。

作成者は、暗黙的な ARIAセマンティクス, または HTML要素のネイティブセマンティクスを上書きしてはいけません。

グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。

レンダリング
ブロックボックス
リスト
  1. menuitem {
  2. display: list-item;
  3. text-align: match-parent;
  4. unicode-bidi: isolate;
  5. }
  6. 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 で採用されておらず、対応しているブラウザもはないと思います。

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>menuitem要素の例 - (Example of menuitem element) | 離珠のHTMLでしぃ!</title>
  6. </head>
  7. <body>
  8. <h1>menuitem要素の例</h1>
  9. <img src="../Img/G01/cafeboard_106l.gif" alt="Cafe board" contextmenu="imiCmmenu">
  10. <menu type="context" id="imiCmmenu">
  11. <menuitem label="Pet the kittens" onclick="kittens.pet()">
  12. <menuitem label="Cuddle with the kittens" onclick="kittens.cuddle()">
  13. <menu label="Feed the kittens">
  14. <menuitem label="Fish" onclick="kittens.feed(fish)">
  15. <menuitem label="Chicken" onclick="kittens.feed(chicken)">
  16. </menu>
  17. </menu>
  18. <p>HTML5.1 にある例示されているソースコードを用いた提示です。
    対応しているブラウザーはないと思うのですが、一応の提示です。
    </p>
  19. <p>提示するにあたり、画像とかIDとかは、あえて変えています。</p>
  20. <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>
  21. </body>
  22. </html>

このサンプルへのリンクです。
(./exmenuitem.htm)

JSONデータ
JSON形式での、データのイメージです。
  1. {
  2. "menuitem": {
  3. "check": "2024-09-01",
  4. "group": "List",
  5. "element": "- X EMPTY -- menu item. (Void elements.) [None] --",
  6. "attlist": {
  7. "%Global;": "",
  8. "type": "CDATA #IMPLIED -- Type of command --",
  9. "label": "CDATA #IMPLIED -- User-visible label --",
  10. "icon": "CDATA #IMPLIED -- Icon for the command --",
  11. "disabled": "(disabled) #IMPLIED -- Whether the command or control is disabled --",
  12. "checked": "(checked) #IMPLIED -- Whether the command or control is checked --",
  13. "radiogroup": "CDATA #IMPLIED -- Name of group of commands to treat as a radio button group --",
  14. "default": "(default) #IMPLIED -- Mark the command as being a default command --",
  15. },
  16. "comment": "メニュー項目 (menu item)",
  17. "point": "ユーザーがポップアップメニュー (コンテキストメニュー) から呼び出すことができるコマンドを表します。",
  18. "description": [
  19. "ユーザーがポップアップメニュー(コンテキストメニュー)から呼び出すことができるコマンドを表します。",
  20. "type, label, icon, disabled, checked, radiogroupの一つ以上を使うmenuitem要素は、新しいコマンドを定義します。",
  21. "HTML5.1 で提案されただけで、HTML Living Standard で採用されておらず、対応しているブラウザもはないと思います。",
  22. ],
  23. "kind": "Void",
  24. "categories": "None",
  25. "used": "menu (menuitem)*",
  26. "contentmodel": "%Nothing",
  27. "tag": [
  28. "-",
  29. "X",
  30. ],
  31. "attributes": {
  32. "type": "コマンドの種類",
  33. "label": "ユーザーに見えるラベル",
  34. "icon": "コマンドのアイコン",
  35. "disabled": "コマンドまたはコントロールが無効かどうか",
  36. "checked": "コマンドまたはコントロールがチェックされているかどうか",
  37. "radiogroup": "ラジオボタングループとして扱うコマンドのグループ名",
  38. "default": "コマンドをデフォルトコマンドとしてマークする",
  39. "title": "コマンドを説明するヒント",
  40. },
  41. "dominterface": "HTMLMenuItemElement",
  42. "rendering": [
  43. "Lists",
  44. "Bidirectional",
  45. ],
  46. "reference": [
  47. {
  48. "title": "HTML Living Standard. 16.2 Non-conforming features.",
  49. "href": "https://html.spec.whatwg.org/multipage/obsolete.html#non-conforming-features",
  50. "heading": "HTML Living Standard. 16.2 Non-conforming features",
  51. "sub": "Last Updated 27 August 2024",
  52. },
  53. {
  54. "title": "HTML 5.1 W3C Recommendation. 4.11.4. The menuitem element. W3C Recommendation, 1 November 2016.",
  55. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/interactive-elements.html#the-menuitem-element",
  56. "heading": "HTML 5.1 W3C 勧告. 4.11.4. The menuitem element",
  57. "sub": "W3C勧告、2016年11月1日",
  58. },
  59. {
  60. "title": "MDN Web Docs. HTML <menuitem>",
  61. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/menuitem",
  62. "heading": "<menuitem> - HTML: ハイパーテキストマークアップ言語 | MDN",
  63. },
  64. ],
  65. "version": {
  66. "first": "HTML5.1",
  67. "latest": "HTML5.1",
  68. },
  69. }
  70. }

注意: 簡易に描画する為に、各項目の後ろに , を付与しています。JSON の形式では、末尾の項目の後には , は付けません。

最終確認日

2024-09-01


2.使用可能な箇所

menu要素 に
配置できます。

menu要素に配置できます。


3.配置できるコンテンツ

配置可能なコンテンツは
ありません。

menuitem要素は、(内容・コンテンツ・Content)を持つことができない空要素です。

menuitem要素は、属性(属性値)によって指定されたメニュー項目を表します。


4.属性

グローバル属性と、
type,
label,
icon,
disabled,
checked,
radiogroup,
default を
設定できます。

menuitemは、グローバル属性type属性, label属性, icon属性, disabled属性, checked属性, radiogroup属性, default属性 を設定できます。
また、グローバル属性である title属性ですが、この要素では特別な意味を持ちます。

  1. <img src="../Img/G01/cafeboard_106l.gif" alt="Cafe board" contextmenu="imiCm400">
  2. <menu type="context" id="imiCm400">
  3. <menuitem label="sample01" onclick="alert('さんぷる1')">
  4. </menu>

この雛型の 3 行目のmenuitem要素を置き換えてデモとしています。

例示は、ただソースコードをそのまま記述しただけであり、menuitem要素に対応しているブラウザーは現在はないと思います。

例示では空要素のmenuitem要素として記述していますが、対応していない要素で通常要素として処理されているようです。

Cafe board

type属性

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

type属性は、コマンドの種類を示します。関連するアクションを持つ通常のコマンドか、トグル可能な状態やオプションか、アイテムのリストから1つのアイテムを選択するかのいずれかです。

typeは、次のキーワード(keywords)と状態(states)を持つ列挙属性(enumerated attribute)です。

command
この要素は、関連するアクションを持つ通常のコマンドを表す。
checkbox
この要素は、トグルできる状態やオプションを表します。
radio
この要素は、アイテムのリストから1つのアイテムを選択することを表します。

列挙属性と呼ばれる一部の属性は、有限の状態セットを取ります。このような属性の状態は、属性の値、各属性の仕様で指定されたキーワード/状態マッピングのセット、および属性の仕様で指定できる 2 つの特殊な状態を組み合わせることによって生成されます。これらの特殊な状態は、無効な値のデフォルトと欠落した値のデフォルトです。
この属性の欠落値のデフォルトは command の状態です。

Cafe board

label属性

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

label属性は、ユーザーに表示されるコマンド名を与える。この属性が指定された場合、その値は空文字列であってはなりません。

Cafe board

icon属性

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

icon属性は、コマンドを表す画像を与えます。属性が指定された場合、属性の値は空白で囲まれた有効なURLでなければなりません。属性の値が空文字列でない場合、アイコンの絶対URLを取得するには、属性の値を要素からの相対値で解決しなければなりません。属性が存在しないか、属性値が空文字列であるか、属性値の解析に失敗した場合、アイコンは存在しません。

Cafe board

disabled属性

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

disabled属性は、ブーリアン属性で、存在する場合、現在の状態ではコマンドが使用できないことを示す。

Cafe board

checked属性

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

checked属性は、ブーリアン属性で、存在すればコマンドが選択されていることを示します。type属性がCheckbox状態かRadio状態でない限り、この属性は省略されなければなりません。

Cafe board

radiogroup属性

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

radiogroup属性は、type属性が値 「radio 」であるコマンドに対して、コマンド自身がトグルされる時にトグルされるコマンドのグループの名前を与えます。名前のスコープは親要素の子リストです。type属性がRadio状態でない限り、属性は省略されなければなりません。指定された場合、属性の値は空でない文字列でなければなりません。

Cafe board

default属性

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

default属性は、もし存在すれば、ユーザーがメニューを使う代わりにメニューの主題を直接起動した場合に呼び出されるコマンドであることを示します。default属性は、ブーリアン属性です。

使い方が良くわかりません。

title属性

  1. <menuitem type="command" label="sample01" onclick="alert('さんぷる1')" title="これはソースコードの例示です。">

title属性は、グローバル属性ですが、この要素に関する特別なセマンティクスがあります。title属性は、コマンドを説明するヒントを与えます。

Cafe board

5.Web API

menuitem要素を
直接表す
プロパティは
ありません。

menuitemを表すプロパティはないので、documentquerySelectorAll()メソッドで条件を絞って、要素のリストを取得する方法があります。この時に取得できるのはHTMLMenuItemElement オブジェクトのリストです。例では属性セレクタ要素セレクタ子結合子menu[id="imiCm500"] > menuitemと指定して、menuitemのリストを取得しています。documentgetElementById()メソッドmenuを取得してから、そのElementquerySelectorAll()メソッドを用いるとか、状況, 目的によりいろいろあります。

Cafe board

この例示のmenuitemは、
"〇〇"です。

  1. <img src="../Img/G01/cafeboard_106l.gif" alt="Cafe board" contextmenu="imiCm500">
  2. <menu type="context" id="imiCm500">
  3. <menuitem type="radio" label="radio01" radiogroup="group01"></menuitem>
  4. <menuitem type="radio" label="radio02" radiogroup="group01"></menuitem>
  5. <menuitem type="command" label="sample01" onclick="alert('さんぷる1')"></menuitem>
  6. </menu>
  7. <p>このページの説明は、
  8. "<code id="JHSAMPLE051">〇〇</code>"です。</p>
  9. <script>
  10. document.addEventListener("DOMContentLoaded", function() {
  11. var vaMenuitem = document.querySelectorAll("menu[id='imiCm500'] > menuitem");
  12. var vaText = '';
  13. for (var i = 0; i < vaMenuitem.length; i++){
  14. vsText = vsText + vaMenuitem[i].getAttribute("label") + ' ';
  15. }
  16. if (vsText) {
  17. document.getElementById("JHSAMPLE051").textContent = vsText;
  18. }
  19. });
  20. </script>

menuitemの一覧から、labelの値を取得する例です。例示で表示する為に、HTML文書の読み込みと解析が終了した時に処理するコードとしています。また、ブラウザが対応してない要素で空要素であるという事から、検証用として通常要素の様に閉じタグを記述しています。


6.レンダリング

  1. menuitem {
  2. display: list-item;
  3. unicode-bidi: isolate;
  4. }
  5. menuitem[type=checkbox i],
  6. menuitem[type=radio i] {
  7. display: inline-block;
  8. }

menuitem要素は、ブロックレベルのブロックコンテナであるボックスを生成します。 (マーカーの分のコンテナボックスも生成します。)

ブロックフォーマットコンテキストに参加して、ブロックフォーマットコンテキストを継承, 確立します。もし、インラインフォーマットコンテキストに参加するコンテンツのみを含む場合は、新しいインラインフォーマットコンテキストを確立します。次に、すべてのインラインコンテンツをラップするルートインラインボックスも生成します。

unicode-bidi は、置換されない要素のレンダリングでの Bidirectional text(双方向テキスト) に於いての期待される仕様の様です。

type属性の値が checkbox, radio であるmenuitem要素は、インラインレベルのブロックコンテナボックス(インラインブロック)を生成します。

menuitem要素は HTML5.1 で仕様が記述されていますが、CSS でのレンダリングについての記述は見当たりません。例示などはあるので、そこから同等の描画の要素のレンダリングの記述から推測したのが、この記述となります。あくまで学習の参考までに。


7.気を付ける点

現行では、
ほとんど未対応の
要素です。

menuitemは、HTML5.1 で提案されましたが、HTML5.2 で廃止され、ほとんど対応したブラウザなどがありません。また、contextmenu属性も、HTML Living Standard では 不適合機能 と記されています。
よって、カスタムコンテキストメニューを実装するには、この要素, 属性はないものとして、Elementcontextmenuイベントを処理するスクリプトを使用します。


8.付記