Skip to content

Commit 0e72e8b

Browse files
Merge pull request #178 from JLG-WOCFR-DEV/codex/update-accessible-name-for-search-input
Improve command palette accessibility
2 parents 03016c1 + 027c8a3 commit 0e72e8b

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

supersede-css-jlg-enhanced/assets/js/ux.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@
7979
};
8080

8181
$(document).ready(function() {
82+
const localizedData = (typeof window !== 'undefined' && typeof window.SSC !== 'undefined' && window.SSC)
83+
? window.SSC
84+
: {};
85+
const i18n = (typeof localizedData.i18n === 'object' && localizedData.i18n !== null)
86+
? localizedData.i18n
87+
: {};
88+
const commandPaletteTitle = i18n.commandPaletteTitle || 'Supersede CSS command palette';
89+
const commandPaletteSearchPlaceholder = i18n.commandPaletteSearchPlaceholder || 'Navigate or run an action…';
90+
const commandPaletteSearchLabel = i18n.commandPaletteSearchLabel || 'Command palette search';
91+
8292
// --- Dark/Light Theme Toggle ---
8393
const themeToggle = $('#ssc-theme');
8494
const body = $('body');
@@ -199,9 +209,10 @@
199209
// --- Command Palette (⌘K) ---
200210
const cmdkButton = $('#ssc-cmdk');
201211
const cmdkPanelHtml = `
202-
<div id="ssc-cmdp" role="dialog" aria-modal="true" aria-hidden="true" aria-label="Palette de commandes Supersede CSS" tabindex="-1">
212+
<div id="ssc-cmdp" role="dialog" aria-modal="true" aria-hidden="true" aria-label="${commandPaletteTitle}" tabindex="-1">
203213
<div class="panel" role="document">
204-
<input type="text" id="ssc-cmdp-search" placeholder="Naviguer ou lancer une action..." style="width: 100%; padding: 12px; border: none; border-bottom: 1px solid var(--ssc-border); font-size: 16px;">
214+
<label for="ssc-cmdp-search" class="screen-reader-text">${commandPaletteSearchLabel}</label>
215+
<input type="text" id="ssc-cmdp-search" placeholder="${commandPaletteSearchPlaceholder}" style="width: 100%; padding: 12px; border: none; border-bottom: 1px solid var(--ssc-border); font-size: 16px;">
205216
<ul id="ssc-cmdp-results"></ul>
206217
</div>
207218
</div>`;

supersede-css-jlg-enhanced/src/Admin/Admin.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ public function assets(string $hook): void {
277277
'rest' => [
278278
'root' => esc_url_raw(rest_url('ssc/v1/')),
279279
'nonce' => wp_create_nonce('wp_rest')
280-
]
280+
],
281+
'i18n' => [
282+
'commandPaletteTitle' => esc_attr__('Supersede CSS command palette', 'supersede-css-jlg'),
283+
'commandPaletteSearchPlaceholder' => esc_attr__('Navigate or run an action…', 'supersede-css-jlg'),
284+
'commandPaletteSearchLabel' => esc_html__('Command palette search', 'supersede-css-jlg'),
285+
],
281286
]);
282287
}
283288
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { test, expect } = require('@playwright/test');
2+
3+
const ADMIN_PATH = '/wp-admin/admin.php?page=supersede-css-jlg';
4+
const DEFAULT_USERNAME = process.env.WP_USERNAME || 'admin';
5+
const DEFAULT_PASSWORD = process.env.WP_PASSWORD || 'password';
6+
7+
async function authenticate(page, adminUrl, credentials) {
8+
const loginUrl = `/wp-login.php?redirect_to=${encodeURIComponent(adminUrl)}`;
9+
await page.goto(loginUrl, { waitUntil: 'domcontentloaded' });
10+
11+
const usernameInput = page.locator('#user_login');
12+
if (await usernameInput.isVisible()) {
13+
await usernameInput.fill(credentials.username);
14+
await page.locator('#user_pass').fill(credentials.password);
15+
await Promise.all([
16+
page.waitForNavigation({ waitUntil: 'networkidle' }),
17+
page.locator('#wp-submit').click(),
18+
]);
19+
}
20+
21+
await page.goto(adminUrl, { waitUntil: 'networkidle' });
22+
}
23+
24+
test.describe('Command palette accessibility', () => {
25+
test('search input exposes translated accessible name', async ({ page }, testInfo) => {
26+
const baseURL = testInfo.project.use.baseURL || 'http://localhost:8889';
27+
const adminUrl = new URL(ADMIN_PATH, baseURL).toString();
28+
29+
await authenticate(page, adminUrl, {
30+
username: DEFAULT_USERNAME,
31+
password: DEFAULT_PASSWORD,
32+
});
33+
34+
await page.waitForFunction(
35+
() => Boolean(window.SSC && window.SSC.i18n && window.SSC.i18n.commandPaletteSearchLabel)
36+
);
37+
const expectedLabel = await page.evaluate(() => window.SSC.i18n.commandPaletteSearchLabel);
38+
39+
const commandPaletteButton = page.locator('#ssc-cmdk');
40+
await expect(commandPaletteButton).toBeVisible();
41+
await commandPaletteButton.click();
42+
43+
const searchInput = page.locator('#ssc-cmdp-search');
44+
await expect(searchInput).toBeVisible();
45+
await expect(searchInput).toHaveAccessibleName(expectedLabel);
46+
});
47+
});

0 commit comments

Comments
 (0)