From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/htmldialogelement/cancel_event/index.html | 122 +++++++++++++++++ files/ja/web/api/htmldialogelement/index.html | 147 +++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 files/ja/web/api/htmldialogelement/cancel_event/index.html create mode 100644 files/ja/web/api/htmldialogelement/index.html (limited to 'files/ja/web/api/htmldialogelement') diff --git a/files/ja/web/api/htmldialogelement/cancel_event/index.html b/files/ja/web/api/htmldialogelement/cancel_event/index.html new file mode 100644 index 0000000000..ff339a0b1b --- /dev/null +++ b/files/ja/web/api/htmldialogelement/cancel_event/index.html @@ -0,0 +1,122 @@ +--- +title: 'HTMLDialogElement: cancel イベント' +slug: Web/API/HTMLDialogElement/cancel_event +tags: + - API + - Event + - HTML DOM + - HTMLDialogElement + - NeedsExample + - cancel + - events + - イベント +translation_of: Web/API/HTMLDialogElement/cancel_event +--- +
{{APIRef}}
+ +

cancel イベントは、ユーザーが現在開いているダウアログを閉じたいと操作したときに {{HTMLElement("dialog")}} に発生します。例えば、ユーザーがブラウザーの UI の中で Esc キーを押したり、「ダイアログを閉じる」ボタンをクリックしたりしたりしたときにブラウザーがこのイベントを発生させることがあります。

+ + + + + + + + + + + + + + + + + + + + +
バブリングなし
キャンセル
インターフェイス{{domxref("Event")}}
イベントハンドラープロパティ{{domxref("GlobalEventHandlers/oncancel", "oncancel")}}
+ +

+ +

ライブ例

+ +

HTML

+ +
<dialog class="example-dialog">
+    <button class="close" type="reset">Close</button>
+</dialog>
+
+<button class="open-dialog">Open dialog</button>
+
+<div class="result"></div>
+ + + +

JS

+ +
const result = document.querySelector('.result');
+
+const dialog = document.querySelector('.example-dialog');
+
+dialog.addEventListener('cancel', (event) => {
+  result.textContent = 'dialog was canceled';
+});
+
+const openDialog = document.querySelector('.open-dialog');
+openDialog.addEventListener('click', () => {
+  if (typeof dialog.showModal === 'function') {
+      dialog.showModal();
+      result.textContent = '';
+  } else {
+      result.textContent = 'The dialog API is not supported by this browser';
+  }
+});
+
+const closeButton = document.querySelector('.close');
+closeButton.addEventListener('click', () => {
+    dialog.close();
+});
+
+ +

結果

+ +

{{ EmbedLiveSample('Live_example', '100%', '100px') }}

+ +

仕様書

+ + + + + + + + + + + + + + +
仕様書状態
{{ SpecName('HTML WHATWG', 'indices.html#event-cancel', 'cancel') }}{{Spec2('HTML WHATWG')}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.HTMLDialogElement.cancel_event")}}

+ +

関連情報

+ + diff --git a/files/ja/web/api/htmldialogelement/index.html b/files/ja/web/api/htmldialogelement/index.html new file mode 100644 index 0000000000..833336ff78 --- /dev/null +++ b/files/ja/web/api/htmldialogelement/index.html @@ -0,0 +1,147 @@ +--- +title: HTMLDialogElement +slug: Web/API/HTMLDialogElement +tags: + - API + - Experimental + - HTML DOM + - HTMLDialogElement + - Interface + - Reference + - インターフェイス +translation_of: Web/API/HTMLDialogElement +--- +
{{APIRef("HTML DOM")}}{{SeeCompatTable}}
+ +

HTMLDialogElement インターフェイスは {{HTMLElement("dialog")}} 要素を操作するメソッドを提供します。 {{domxref("HTMLElement")}} インターフェースからプロパティとメソッドを継承しています。

+ +

{{InheritanceDiagram(600, 80)}}

+ +

プロパティ

+ +

親である {{domxref("HTMLElement")}} からプロパティを継承しています。

+ +
+
{{domxref("HTMLDialogElement.open")}}
+
{{domxref("Boolean")}} で、ダイアログが対話可能であることを示す {{htmlattrxref("open", "dialog")}} 属性の値を反映します。
+
{{domxref("HTMLDialogElement.returnValue")}}
+
{{domxref("DOMString")}} で、ダイアログの返値を設定させたり返したりします。
+
+ +

メソッド

+ +

親である {{domxref("HTMLElement")}} からメソッドを継承しています。

+ +
+
{{domxref("HTMLDialogElement.close()")}}
+
ダイアログを閉じます。任意で引数として {{domxref("DOMString")}} を渡すことができ、これがダイアログの returnValue を更新します。
+
{{domxref("HTMLDialogElement.show()")}}
+
ダイアログをモードレスで開きます。すなわち、その間のダイアログの外のコンテンツとの対話ができます。
+
{{domxref("HTMLDialogElement.showModal()")}}
+
ダイアログをモーダルで、他のダイアログがあればその最も上に表示します。ダイアログの外との対話はブロックされます。
+
+ +

イベント

+ +
+
{{domxref("HTMLDialogElement/close_event", "close")}}
+
ダイアログが閉じられたときに発生します。
+ {{domxref("GlobalEventHandlers/onclose", "onclose")}} プロパティからも利用できます。
+
+ +

+ +

以下の例は単純なボタンを表示し、クリックすると、 {{htmlelement("dialog")}} でフォームを {{domxref("HTMLDialogElement.showModal()")}} 関数によって開きます。そこから Cancel ボタンを押して ({{domxref("HTMLDialogElement.close()")}} 関数で) ダイアログを閉じるか、 submit ボタンでフォームを送信するかします。

+ +
  <!-- Simple pop-up dialog box, containing a form -->
+  <dialog id="favDialog">
+    <form method="dialog">
+      <section>
+        <p><label for="favAnimal">Favorite animal:</label>
+        <select id="favAnimal" name="favAnimal">
+          <option></option>
+          <option>Brine shrimp</option>
+          <option>Red panda</option>
+          <option>Spider monkey</option>
+        </select></p>
+      </section>
+      <menu>
+        <button id="cancel" type="reset">Cancel</button>
+        <button type="submit">Confirm</button>
+      </menu>
+    </form>
+  </dialog>
+
+  <menu>
+    <button id="updateDetails">Update details</button>
+  </menu>
+
+  <script>
+    (function() {
+      var updateButton = document.getElementById('updateDetails');
+      var cancelButton = document.getElementById('cancel');
+      var dialog = document.getElementById('favDialog');
+      dialog.returnValue = 'favAnimal';
+
+      function openCheck(dialog) {
+        if(dialog.open) {
+          console.log('Dialog open');
+        } else {
+          console.log('Dialog closed');
+        }
+      }
+
+      // Update button opens a modal dialog
+      updateButton.addEventListener('click', function() {
+        dialog.showModal();
+        openCheck(dialog);
+      });
+
+      // Form cancel button closes the dialog box
+      cancelButton.addEventListener('click', function() {
+        dialog.close('animalNotChosen');
+        openCheck(dialog);
+      });
+
+    })();
+  </script>
+ +
+

メモ: この例は GitHub 上の htmldialogelement-basic (ライブで表示) として見つけることができます。

+
+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('HTML WHATWG', "#htmlinputelement", "HTMLInputElement")}}{{Spec2('HTML WHATWG')}}
{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '<dialog>')}}{{Spec2('HTML5.1')}}初回定義
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.HTMLDialogElement")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf