Skip to content

Commit

Permalink
improve the example w/ :target, add Safari support
Browse files Browse the repository at this point in the history
Closes una#2
  • Loading branch information
Marcy Sutton committed Oct 13, 2016
1 parent 31eb6ca commit 1266e50
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
12 changes: 9 additions & 3 deletions comparisons/components/modal/html.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<a class="modalTrigger" href="#modalDialog1">
Click Me
<a class="modalTrigger" id="modalTrigger"
href="#modalDialog1">
Open dialog
</a>

<dialog class="modal" id="modalDialog1"
tabindex="-1" role="dialog">
<p>Hello Beautiful!</p>
<div>
<a href="#modalTrigger" aria-label="Close">
&times;
</a>
<p>Hello Beautiful!</p>
</div>
</dialog>
20 changes: 9 additions & 11 deletions comparisons/components/modal/scss.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Modal is visually hidden until focused.
// This only sort-of works: you can't close
// the dialog with the escape key, and it can't
// contain anything interactive for 2 reasons:
// you wouldn't be able to tab without blurring
// the dialog, and they'd be focusable when
// the dialog is closed (a poor keyboard experience).
.modal {
// Modal is hidden until it matches an anchor
// target. This only sort-of works, as you can't close
// it with the escape key or trap focus inside of it.
.modal {
opacity: 0;
visibility: hidden;
}

// modal fades in when button
// is in focus (i.e. clicked on)
.modal:focus {
// modal fades in when it matches
// an anchor link (i.e. clicked on)
#modalDialog:target {
opacity: 1;
visibility: hidden;
}
37 changes: 21 additions & 16 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,34 +149,39 @@ <h4>CODEPEN</h4><p data-height="265" data-theme-id="light" data-slug-hash="pEVjw
<div data-code="html" class="code html">
<h4>HTML</h4>
<div data-lang="markup" class="code-block language-markup">
<pre><code>&lt;a class=&quot;modalTrigger&quot; href=&quot;#modalDialog1&quot;&gt;
Click Me
<pre><code>&lt;a class=&quot;modalTrigger&quot; id=&quot;modalTrigger&quot;
href=&quot;#modalDialog1&quot;&gt;
Open dialog
&lt;/a&gt;

&lt;dialog class=&quot;modal&quot; id=&quot;modalDialog1&quot;
&lt;dialog class=&quot;modal&quot; id=&quot;modalDialog1&quot;
tabindex=&quot;-1&quot; role=&quot;dialog&quot;&gt;
&lt;p&gt;Hello World!&lt;/p&gt;
&lt;/dialog&gt;</code></pre>
&lt;div&gt;
&lt;a href=&quot;#modalTrigger&quot; aria-label=&quot;Close&quot;&gt;
&amp;times;
&lt;/a&gt;
&lt;p&gt;Hello Beautiful!&lt;/p&gt;
&lt;/div&gt;
&lt;/dialog&gt;
</code></pre>
</div>
</div>
<div data-code="scss" class="code scss">
<h4>SCSS</h4>
<div data-lang="scss" class="code-block language-scss">
<pre><code>// Modal is visually hidden until focused.
// This only sort-of works: you can't close
// the dialog with the escape key, and it can't
// contain anything interactive for 2 reasons:
// you wouldn't be able to tab without blurring
// the dialog, and they'd be focusable when
// the dialog is closed (a poor keyboard experience).
.modal {
<pre><code>// Modal is hidden until it matches an anchor
// target. This only sort-of works, as you can't close
// it with the escape key or trap focus inside of it.
.modal {
opacity: 0;
visibility: hidden;
}

// modal fades in when button
// is in focus (i.e. clicked on)
.modal:focus {
// modal fades in when it matches
// an anchor link (i.e. clicked on)
#modalDialog:target {
opacity: 1;
visibility: hidden;
}</code></pre>
</div>
</div>
Expand Down

0 comments on commit 1266e50

Please sign in to comment.