mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-04 14:11:22 +09:00
refactor(frontend): Phase 5 §8.2 — sanitize sidebar SVG icons + AI shortcut a11y
Per docs/plans/FRONTEND_UX_TAILWIND_CLEANUP_PLAN.md §8.2 (A1/A8, A2). - Sidebar icons were injected via dangerouslySetInnerHTML. Core icons are trusted constants, but plugin-contributed nav items flow through the same path and could supply arbitrary SVG. Added utils/sanitizeSvg.js: an allowlist sanitizer (DOMParser-based, caches results) that keeps only safe SVG shape elements/attributes and drops scripts/event handlers/external refs. Wired both Sidebar icon sites through it — zero visual change (verified via screenshot). - AI Alt+A shortcut: added a visible title tooltip + aria-keyshortcuts on the chat bubble (discoverable), and made the global handler skippable via localStorage 'sk_ai_shortcut' = 'off'. Verified: npm run build passes; 0 lint errors; dashboard screenshot confirms sidebar icons still render. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d6b631ec34
commit
c3eb51f3d2
4 files changed
+80
-3
No files matched your search
@@ -9,6 +9,7 @@ import WorkspaceSwitcher from './WorkspaceSwitcher';
|
||||
import NotificationBell from './NotificationBell';
|
||||
import { SIDEBAR_CATEGORIES, CATEGORY_LABELS, SIDEBAR_PRESETS, getHiddenItemIds, getVisibleItems, applyWorkspaceNavPermissions } from './sidebarItems';
|
||||
import { useContributions } from '../plugins/contributions';
|
||||
import { sanitizeSvgInner } from '../utils/sanitizeSvg';
|
||||
|
||||
const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {} }) => {
|
||||
const { user, logout, updateUser } = useAuth();
|
||||
@@ -222,7 +223,7 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {
|
||||
>
|
||||
<svg className="nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||||
aria-hidden="true" focusable="false"
|
||||
dangerouslySetInnerHTML={{ __html: item.icon }}
|
||||
dangerouslySetInnerHTML={{ __html: sanitizeSvgInner(item.icon) }}
|
||||
/>
|
||||
{item.label}
|
||||
</NavLink>
|
||||
@@ -246,7 +247,7 @@ const Sidebar = ({ mobileOpen = false, isMobile = false, onMobileClose = () => {
|
||||
>
|
||||
<svg className="nav-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
||||
aria-hidden="true" focusable="false"
|
||||
dangerouslySetInnerHTML={{ __html: sub.icon }}
|
||||
dangerouslySetInnerHTML={{ __html: sanitizeSvgInner(sub.icon) }}
|
||||
/>
|
||||
{sub.label}
|
||||
</NavLink>
|
||||
|
||||
@@ -11,8 +11,12 @@ const AIAssistant = () => {
|
||||
const { isAuthenticated } = useAuth();
|
||||
const { isOpen, toggle, isStreaming, unread, pageContext } = useServerkitAI();
|
||||
|
||||
// Alt+A toggles the assistant (ignored while typing in a field).
|
||||
// Alt+A toggles the assistant (ignored while typing in a field). Users who
|
||||
// find the global shortcut intrusive can disable it by setting
|
||||
// localStorage 'sk_ai_shortcut' to 'off'; the bubble's title/aria-label
|
||||
// keeps the binding discoverable for everyone else.
|
||||
useEffect(() => {
|
||||
if (localStorage.getItem('sk_ai_shortcut') === 'off') return undefined;
|
||||
const onKeyDown = (e) => {
|
||||
if (!e.altKey || (e.key !== 'a' && e.key !== 'A')) return;
|
||||
const t = document.activeElement;
|
||||
|
||||
@@ -13,6 +13,8 @@ const ChatBubble = ({ open, unread, streaming, raised, onToggle }) => (
|
||||
].filter(Boolean).join(' ')}
|
||||
onClick={onToggle}
|
||||
aria-label={open ? 'Close assistant (Alt+A)' : 'Open assistant (Alt+A)'}
|
||||
title={open ? 'Close assistant (Alt+A)' : 'Open assistant (Alt+A)'}
|
||||
aria-keyshortcuts="Alt+A"
|
||||
aria-expanded={open}
|
||||
aria-controls="sk-ai-drawer"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user