Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Stop nesting the CatalogCard action in a button

Juan Denis44ff9d419c06
diff --git a/frontend/src/components/ds/CatalogCard.jsx b/frontend/src/components/ds/CatalogCard.jsx
index 93f68663..af4bc3fe 100644
--- a/frontend/src/components/ds/CatalogCard.jsx
+++ b/frontend/src/components/ds/CatalogCard.jsx
@@ -1,5 +1,6 @@
import { Star } from 'lucide-react';
import { cn } from '@/lib/utils';
+import { Button } from '@/components/ui/button';
import { t } from '@/i18n/t';
/**
@@ -22,6 +23,11 @@ import { t } from '@/i18n/t';
*
* One tag, one action. Version, author and counts go in `sub` / `facts` as
* plain text rather than as more badges.
+ *
+ * With `onClick`, the title is the real button (keyboard and screen readers)
+ * and the rest of the card is a mouse-only shortcut to it. The card itself is
+ * never a button: it would contain the action button, and nested controls
+ * give assistive technology two conflicting targets.
*/
export function CatalogCard({
icon,
@@ -36,37 +42,39 @@ export function CatalogCard({
className,
as: Tag = 'li',
}) {
- const handleKeyDown = onClick
- ? (event) => {
- if (event.target !== event.currentTarget) return;
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault();
- onClick(event);
- }
- }
- : undefined;
+ const titleContent = (
+ <>
+ {title}
+ {featured && (
+ <Star
+ size={12}
+ className="sk-catalog-card__featured"
+ aria-label={t('app.catalogCard.featured', 'Featured')}
+ />
+ )}
+ </>
+ );
return (
<Tag
className={cn('sk-catalog-card', onClick && 'is-clickable', className)}
onClick={onClick}
- onKeyDown={handleKeyDown}
- role={onClick ? 'button' : undefined}
- tabIndex={onClick ? 0 : undefined}
>
<div className="sk-catalog-card__head">
{icon && <span className="sk-catalog-card__icon">{icon}</span>}
<span className="sk-catalog-card__id">
- <span className="sk-catalog-card__title">
- {title}
- {featured && (
- <Star
- size={12}
- className="sk-catalog-card__featured"
- aria-label={t('app.catalogCard.featured', 'Featured')}
- />
- )}
- </span>
+ {onClick ? (
+ <Button
+ variant="unstyled"
+ type="button"
+ className="sk-catalog-card__title sk-catalog-card__open"
+ onClick={(event) => { event.stopPropagation(); onClick(event); }}
+ >
+ {titleContent}
+ </Button>
+ ) : (
+ <span className="sk-catalog-card__title">{titleContent}</span>
+ )}
{sub && <span className="sk-catalog-card__sub">{sub}</span>}
</span>
{tag && <span className="sk-catalog-card__tag">{tag}</span>}
diff --git a/frontend/src/styles/components/_design-system.scss b/frontend/src/styles/components/_design-system.scss
index 3f273932..afe59154 100644
--- a/frontend/src/styles/components/_design-system.scss
+++ b/frontend/src/styles/components/_design-system.scss
@@ -1550,7 +1550,7 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
&.is-clickable { cursor: pointer; }
&.is-clickable:hover { border-color: var(--border); background: var(--surface-2); }
- &.is-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
+ &.is-clickable:focus-within { border-color: var(--border); }
&__head { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
&__icon {
@@ -1570,6 +1570,17 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
font-weight: $font-weight-semibold; font-size: $text-sm; color: var(--text);
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
+ &__open {
+ max-width: 100%;
+ padding: 0;
+ border: 0;
+ background: none;
+ font-family: inherit;
+ text-align: start;
+ cursor: pointer;
+
+ &:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
+ }
&__featured { flex-shrink: 0; color: var(--text-faint); fill: currentColor; }
&__sub {
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;