fixed style of clickable card (#28521)
* fixed style of clickable card fixes: #28519 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> * fix aria Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> * use useId instead of passing it Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> --------- Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
426c13967d
commit
38662c86a7
1 changed files with 14 additions and 14 deletions
|
@ -1,32 +1,32 @@
|
|||
import { KeyboardEvent } from "react";
|
||||
import { Card, CardProps } from "@patternfly/react-core";
|
||||
import { KeyboardEvent, useId } from "react";
|
||||
import { Card, CardHeader, CardProps } from "@patternfly/react-core";
|
||||
|
||||
type ClickableCardProps = Omit<CardProps, "onClick"> & {
|
||||
onClick: () => void;
|
||||
};
|
||||
|
||||
export const ClickableCard = ({
|
||||
children,
|
||||
onClick,
|
||||
children,
|
||||
...rest
|
||||
}: ClickableCardProps) => {
|
||||
const id = useId();
|
||||
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
||||
if (e.key === " " || e.key === "Enter" || e.key === "Spacebar") {
|
||||
onClick();
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Card
|
||||
className="keycloak-empty-state-card"
|
||||
role="button"
|
||||
aria-pressed="false"
|
||||
tabIndex={0}
|
||||
isSelectable
|
||||
onKeyDown={onKeyDown}
|
||||
onClick={onClick}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
<Card id={id} isClickable onKeyDown={onKeyDown} onClick={onClick} {...rest}>
|
||||
<CardHeader
|
||||
selectableActions={{
|
||||
onClickAction: onClick,
|
||||
selectableActionId: `input-${id}`,
|
||||
selectableActionAriaLabelledby: id,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</CardHeader>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue