<html lang="en">
<head>
<meta charset="utf-8">
<title>ally.style.focusWithin Example</title>
</head>
<body>
<article id="example-introduction">
<h1><code>ally.style.focusWithin</code> Example</h1>
<p>The ancestry of the focused element should be visible by red borders. The first and the last input are outside of the style scope - they are there to provide focusable elements to verify that the <code>ally-focus-within</code> class is properly removed.</p>
</article>
<div id="example-html">
<main>
<input id="before-input" type="text" value="before styled">
<div class="example">
<div id="first-shadow-host"></div>
<div>
<input id="outer-input" type="text" value="outer input">
</div>
<svg width="50" height="50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<a xlink:href="#void" data-label="svg a[xlink|href]">
<text x="10" y="20" data-label="svg a[xlink|href] text">an SVG</text>
</a>
</svg>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/ally.js/1.4.1/ally.min.js"></script>
</body>
</html>
/* separate blocks because ">>>" or "/deep/" might not be supported and thus render the selector void */
.example.ally-focus-within,
.example .ally-focus-within {
margin: 2px;
border: 2px solid red;
}
.example >>> .ally-focus-within {
margin: 2px;
border: 2px solid red;
}
.example /deep/ .ally-focus-within {
margin: 2px;
border: 2px solid red;
}
svg .ally-focus-within {
outline: 2px red solid;
}
var handle = ally.style.focusWithin();
var input = document.getElementById('before-input');
// create shadow dom structure:
if (document.body.createShadowRoot !== undefined) {
var shadowed = createShadowedContent(
document.getElementById('first-shadow-host'),
'<div id="second-shadow-host"></div><div id="third-shadow-host"></div>'
);
var second = createShadowedContent(
shadowed.getElementById('second-shadow-host'),
'<input id="first-input" type="text" value="::shadow ::shadow input">'
);
createShadowedContent(
shadowed.getElementById('third-shadow-host'),
'<input id="second-input" type="text" value="::shadow ::shadow input">'
);
input = second.querySelector('input');
}
input.focus();
function createShadowedContent(host, html) {
var root = host.createShadowRoot();
root.innerHTML = html;
return root;
}
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |