Skip to content

Commit

Permalink
tweak examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz-nz committed Feb 4, 2024
1 parent 806fcd2 commit 7aa21f9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
26 changes: 14 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
grid-template-columns: 1fr auto;
align-items: center;
}

input {
padding: 8px 10px;
border: 1px solid #ddd;
border-radius: 3px;
}

button {
padding: 8px 10px;
}

output {
margin: 0;
padding: 0;
Expand All @@ -33,20 +33,22 @@

keyboard-control {
grid-column: span 2;

&:not([hidden]) {
display: block;
}

a {
padding: 5px;

border: 1px solid color-mix(in lch, var(--bg, #ddd) 60%, black);
border-radius: 3px;
background: var(--bg, #ddd);

transition: background ease 0.2s;

&[active] {
color: white;
--bg: color-mix(in lch, cyan 80%, black);
}

Expand All @@ -59,11 +61,11 @@
</head>

<body>

<form action="#search">
<input type="search" name="search" value="a search term" autofocus>
<button type="submit">Search</button>

<keyboard-control items="a" loop hidden>
<output>
<a href="#1">a search result</a>
Expand All @@ -77,13 +79,13 @@
<script>
document.querySelector("form").addEventListener("submit", (event) => {
event.preventDefault();

let control = event.target.querySelector('keyboard-control')

control.removeAttribute('hidden');
control.focus();
});

document.querySelectorAll("a").forEach((result) => {
result.addEventListener("select", (event) => {
event.target.focus()
Expand All @@ -106,4 +108,4 @@
</script>
</body>

</html>
</html>
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Here's a usage example:
```html
<script type="module" src="https://cdn.jsdelivr.net/gh/tobz-nz/keyboard-control/keyboard-control.js"></script>

<keyboard-control items="button" selected="active" loop>
<keyboard-control items="li a" selected="active" loop>
<menu>
<li><a href="#1" title="First Link">Link 1</a></li>
<li><a href="#2" title="Second Link" active>Link 2</a></li>
Expand All @@ -22,4 +22,4 @@ And [here's a demo](https://tobz-nz.github.io/keyboard-control/index.html).
| Attribute | Default | Description |
| ----------|---------|------------ |
| items | `[keyboard-target]` | The css selector for elements to control |
| selected | `active` | The CSS selector for the currently selected element (only 1 element can be selected, if more than 1 is, first will be used) |
| selected | `active` | The CSS selector for the currently selected element (only 1 element can be selected, if more than 1 is, first will be used) |

0 comments on commit 7aa21f9

Please sign in to comment.