1. Create the folder and index.html
In this lesson you will build a task-list app with a command palette; by the end you will add tasks, mark them complete and change views with the keyboard. A command palette is a small window that finds an action by its name. GitHub announced general availability of its rebuilt command palette. We use the keyboard-navigation idea in an independent learning product. No GitHub account or connection is needed; the example tasks are fictional test data.
A modern browser and a plain text editor are enough. HTML describes the page structure. You do not install a server, create an account or add packages; the files open on your computer.
Create an empty emr-palitrasi folder. Its tree contains index.html, styles.css, labels.js, palette.js and app.js directly inside emr-palitrasi/. Create them in this order. The complete first file, index.html, follows.
<!doctype html>
<html lang="az">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,">
<link rel="stylesheet" href="styles.css">
<title>İş siyahısı</title>
<script src="labels.js" defer></script>
<script src="palette.js" defer></script>
<script src="app.js" defer></script>
</head>
<body>
<main>
<header><h1 data-text="title"></h1>
<label><span data-text="language"></span>
<select id="language"><option value="az">AZ</option><option value="en">EN</option><option value="ru">RU</option></select>
</label></header>
<p data-text="demoNote"></p>
<form id="addForm">
<label for="input" data-text="inputLabel"></label>
<textarea id="input" rows="3" aria-describedby="help error"></textarea>
<p id="help" data-text="help"></p>
<button data-text="add"></button>
</form>
<p id="error" role="alert"></p>
<button id="show" type="button" data-text="commands"></button>
<p id="status" role="status"></p>
<ul id="tasks" aria-label="Tasks"></ul>
<p id="empty" data-text="empty"></p>
<p data-text="memory"></p>
<dialog id="palette" aria-labelledby="paletteTitle">
<h2 id="paletteTitle" data-text="commands"></h2>
<label for="query" data-text="search"></label>
<input id="query" type="search" autocomplete="off" autofocus>
<ul id="choices"></ul>
<p id="noMatch" role="status" data-text="noMatch"></p>
<button id="close" type="button" data-text="close"></button>
</dialog>
</main>
</body>
</html>
2. Add the styles.css appearance rules
CSS defines rules for element colors and sizes. Save styles.css in the same folder. Focus is the element selected for keyboard input. These rules wrap long task names, show focus and follow the system light or dark theme.
:root { color-scheme: light dark; font: 17px/1.6 system-ui, sans-serif; }
body { margin: 0; background: #f3f6fc; color: #17223a; }
main { max-width: 42rem; margin: 2rem auto; padding: 1.2rem; }
header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h1 { font-size: clamp(1.6rem, 5vw, 2.2rem); }
label { display: block; }
textarea, input, select, button { font: inherit; border: 1px solid #607086; border-radius: .5rem; }
textarea, #query { width: 100%; box-sizing: border-box; padding: .6rem; }
button, select { min-height: 44px; padding: .4rem .8rem; }
button { cursor: pointer; background: #123fad; color: white; }
ul { list-style: none; padding: 0; }
#tasks li { padding: .7rem; margin: .5rem 0; border: 1px solid #9aabc2; border-radius: .6rem; }
#tasks label { display: flex; gap: .7rem; align-items: flex-start; overflow-wrap: anywhere; }
#tasks input { width: 1.3rem; height: 1.3rem; flex: 0 0 auto; margin-top: .3rem; }
#tasks input:checked + span { text-decoration: line-through; }
#error { color: #aa1322; }
:focus-visible { outline: 3px solid #c66a00; outline-offset: 3px; }
dialog { width: min(85vw, 30rem); max-height: 85dvh; box-sizing: border-box; border-radius: .8rem; }
dialog::backdrop { background: #17223ab3; }
#choices button { width: 100%; text-align: start; margin: .3rem 0; }
@media (prefers-color-scheme: dark) {
body { background: #111a2b; color: #edf3ff; }
#error { color: #ffb6bd; }
dialog { background: #18243a; color: #edf3ff; }
button { background: #9dbbff; color: #111a2b; }
}
3. Keep interface translations in labels.js
JavaScript is the language that runs actions in the browser. labels.js creates a text dictionary with matching keys for three languages. Changing language updates buttons and notices; it does not translate task names entered by the user.
const labels = {
az: {
title: 'İş siyahısı', language: 'Dil', demoNote: 'Mətn sahəsindəki işlər uydurma sınaq nümunəsidir.',
inputLabel: 'Hər sətirdə bir iş', help: 'Ən çox 30 iş, hər işdə ən çox 80 işarə.',
add: 'Əlavə et', commands: 'Əmrlər · Ctrl/⌘+K', search: 'Əmr axtarın', close: 'Bağla',
all: 'Hamısını göstər', open: 'Açıq işləri göstər', done: 'Bitən işləri göstər',
empty: 'Bu görünüşdə iş yoxdur.', noMatch: 'Uyğun əmr yoxdur.',
error: 'İş yazın; 30 iş və hər iş üçün 80 işarə həddini yoxlayın.',
count: 'Göstərilən / cəmi / açıq', memory: 'İşlər yalnız bu sessiyadadır. Yeniləmə siyahını silir.',
demo: 'Oxu\nQeyd et'
},
en: {
title: 'Task list', language: 'Language', demoNote: 'The tasks in the text box are fictional test data.',
inputLabel: 'One task per line', help: 'At most 30 tasks, each at most 80 characters.',
add: 'Add', commands: 'Commands · Ctrl/⌘+K', search: 'Find a command', close: 'Close',
all: 'Show all tasks', open: 'Show open tasks', done: 'Show completed tasks',
empty: 'No tasks in this view.', noMatch: 'No matching command.',
error: 'Enter tasks; check the limit of 30 tasks and 80 characters per task.',
count: 'Shown / total / open', memory: 'Tasks last for this session only. Reload clears the list.',
demo: 'Read\nTake notes'
},
ru: {
title: 'Список дел', language: 'Язык', demoNote: 'Дела в текстовом поле — вымышленные тестовые данные.',
inputLabel: 'Одно дело в строке', help: 'Не более 30 дел, не более 80 символов в каждом.',
add: 'Добавить', commands: 'Команды · Ctrl/⌘+K', search: 'Найти команду', close: 'Закрыть',
all: 'Показать все дела', open: 'Показать незавершённые', done: 'Показать завершённые',
empty: 'В этом режиме дел нет.', noMatch: 'Подходящей команды нет.',
error: 'Введите дела; проверьте предел в 30 дел и 80 символов для каждого.',
count: 'Показано / всего / осталось', memory: 'Дела хранятся только в сеансе. Обновление очищает список.',
demo: 'Прочитать\nСделать заметку'
}
};
4. Find actions by name with palette.js
A function is a named group of instructions. palette.js defines two functions that filter actions using the search text and open the window. They run after app.js has loaded. The three actions change only which tasks are shown.
'use strict';
function commands() {
choices.replaceChildren();
['all', 'open', 'done'].filter(key => text(key).toLocaleLowerCase(lang).includes(query.value.trim().toLocaleLowerCase(lang))).forEach(key => {
const row = document.createElement('li'), button = document.createElement('button');
button.textContent = text(key);
button.onclick = () => { mode = key; render(); palette.close(); };
row.append(button); choices.append(row);
});
byId('noMatch').hidden = choices.childElementCount !== 0;
}
function openPalette() {
returnFocus = document.activeElement;
query.value = ''; commands(); palette.showModal(); query.focus();
}
5. Connect tasks and keyboard events in app.js
app.js checks input lines and adds them to the task list. Invalid input rejects the whole new batch while preserving existing tasks. textContent displays user text without executing it as HTML.
The browser dialog element opens the window and supports Escape to close it. Arrow keys select an action; Enter runs it. Closing restores focus to the previous element. Save this complete file as well.
'use strict';
const byId = id => document.getElementById(id);
const input = byId('input'), list = byId('tasks');
const palette = byId('palette'), query = byId('query');
const choices = byId('choices'), language = byId('language');
const tasks = [];
let lang = 'az', mode = 'all', nextId = 0, returnFocus;
const text = key => labels[lang][key];
function render() {
const focusId = document.activeElement.dataset.task;
list.replaceChildren();
const shown = tasks.filter(t => mode === 'all' || t.done === (mode === 'done'));
shown.forEach(task => {
const row = document.createElement('li');
const label = document.createElement('label');
const box = document.createElement('input');
box.type = 'checkbox'; box.checked = task.done;
box.dataset.task = task.id;
const name = document.createElement('span');
name.textContent = task.name;
box.onchange = () => { task.done = box.checked; render(); };
label.append(box, name); row.append(label); list.append(row);
});
byId('status').textContent = `${text('count')}: ${shown.length} / ${tasks.length} / ${tasks.filter(t => !t.done).length}`;
byId('empty').hidden = shown.length !== 0;
if (focusId) (list.querySelector(`[data-task="${focusId}"]`) || byId('show')).focus();
}
byId('addForm').onsubmit = event => {
event.preventDefault();
const lines = input.value.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
if (!lines.length || tasks.length + lines.length > 30 || lines.some(s => Array.from(s).length > 80)) {
byId('error').textContent = text('error'); return;
}
lines.forEach(name => tasks.push({ id: String(++nextId), name, done: false }));
input.value = ''; byId('error').textContent = ''; render();
};
byId('show').onclick = openPalette;
byId('close').onclick = () => palette.close();
palette.onclose = () => (returnFocus?.isConnected ? returnFocus : byId('show')).focus();
query.oninput = commands;
palette.onkeydown = event => {
if (event.key === 'Escape') {
event.preventDefault(); palette.close(); return;
}
const buttons = Array.from(choices.querySelectorAll('button'));
if (['ArrowDown', 'ArrowUp'].includes(event.key) && buttons.length) {
event.preventDefault();
const i = buttons.indexOf(document.activeElement);
const step = event.key === 'ArrowDown' ? 1 : -1;
const next = i < 0 ? (step > 0 ? 0 : buttons.length - 1) : (i + step + buttons.length) % buttons.length;
buttons[next].focus();
} else if (event.key === 'Enter' && document.activeElement === query) {
event.preventDefault(); buttons[0]?.click();
}
};
document.onkeydown = event => {
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k') {
event.preventDefault(); palette.open ? palette.close() : openPalette();
}
};
language.onchange = () => {
const wasDemo = input.value === text('demo');
lang = language.value; document.documentElement.lang = lang;
document.title = text('title');
document.querySelectorAll('[data-text]').forEach(el => { el.textContent = text(el.dataset.text); });
list.setAttribute('aria-label', text('title'));
byId('error').textContent = ''; if (wasDemo) input.value = text('demo');
render();
};
language.onchange(); input.value = text('demo');
6. Run, test and make one change
Save all five files as UTF-8 and open index.html in the browser. Select EN and add the demo lines Read and Take notes: two tasks must appear. Focus the first checkbox and press Space: the counters become 2 / 2 / 1. Open the palette with Ctrl+K or Command+K, search completed and press Enter: one task remains. Escape closes the window; phones have the Commands button.
Submit empty text or an 81-character line: an error must appear without losing the two tasks. Input that makes the total exceed 30 is also rejected. Search commands for zzzz: No matching command must appear and Enter must do nothing. An empty view shows a notice. If the page fails, check exact filenames, their shared folder and the script order in index.html.
Exercise: in palette.js change the all, open, done order to done, open, all. Save, reload, add the two tasks again and complete one. Open the palette and press the down arrow, then Enter: the first action must show completed tasks, leaving one visible. Limitations: tasks exist only in memory; reload clears them. There is no account sharing or GitHub connection.

