Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <dialog id="dialog1">
  <a href="#">Lien 1</a>
  <a href="#">Lien 2</a>
  <button type="button" onClick="closeModal(dialog1)">Fermer</button>
</dialog>

<dialog id="dialog2">
  <button type="button" onClick="closeModal(dialog2)">Fermer</button>
  <a href="#test">Ancre</a>
</dialog>

<button type="button" id="btnOpenModal1">Première boîte de dialogue</button>
<button type="button" id="btnOpenModal2">Seconde boîte de dialogue</button>
              
            
!

CSS

              
                .visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

              
            
!

JS

              
                let btnOpenModal1 = document.getElementById("btnOpenModal1");
let dialog1 = document.getElementById("dialog1");

let btnOpenModal2 = document.getElementById("btnOpenModal2");
let dialog2 = document.getElementById("dialog2");

btnOpenModal1.addEventListener("click", function onOpen() {
  if (typeof dialog1.showModal === "function") {
    dialog1.showModal();
    trapFocusIn(dialog1);
  } else {
    console.error(
      "L'API <dialog> n'est pas prise en charge par ce navigateur."
    );
  }
});

btnOpenModal2.addEventListener("click", function onOpen() {
  if (typeof dialog2.showModal === "function") {
    dialog2.showModal();
    trapFocusIn(dialog2);
  } else {
    console.error(
      "L'API <dialog> n'est pas prise en charge par ce navigateur."
    );
  }
});

//ferme une modal
function closeModal(modal) {
  modal.close();
}

//Contraint le focus a rester dans la modal
function trapFocusIn(modal) {
  modal.addEventListener("keydown", function (e) {
    let isTabPressed = e.key === "Tab" || e.keyCode === 9;

    if (!isTabPressed) {
      return;
    }

    let focusableElement = modal.querySelectorAll(
      'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
    );
    let firstFocusableElement = focusableElement[0];
    let lastFocusableElement = focusableElement[focusableElement.length - 1];

    if (e.shiftKey) {
      // if shift key pressed for shift + tab combination
      if (document.activeElement === firstFocusableElement) {
        lastFocusableElement.focus(); // add focus for the last focusable element
        e.preventDefault();
      }
    } else {
      // if tab key is pressed
      if (document.activeElement === lastFocusableElement) {
        // if focused has reached to last focusable element then focus first focusable element after pressing tab
        firstFocusableElement.focus(); // add focus for the first focusable element
        e.preventDefault();
      }
    }
  });
}

              
            
!
999px

Console