Skip to content

Commit

Permalink
Merge pull request #79 from archita-2810/main
Browse files Browse the repository at this point in the history
enhance alert box accessbility #52 issue
  • Loading branch information
harshmangalam authored Oct 15, 2024
2 parents cd8f06f + b58c3c7 commit 6f31617
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/components/ui/alert.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
import { component$ } from "@builder.io/qwik";
import { component$, useStore } from "@builder.io/qwik";

type Props = {
text: string;
status: "alert-info" | "alert-success" | "alert-warning" | "alert-error";
onClose?: () => void;
};

export const Alert = component$((props: Props) => {
const { text, status = "alert-info" } = props;
const { text, status = "alert-info", onClose } = props;
const store = useStore({ isVisible: true });

const handleClose = () => {
store.isVisible = false;
if (onClose) {
onClose();
}
};

if (!store.isVisible) return null;

return (
<div class={["alert", status]}>
<div
role="alert"
aria-live="assertive"
aria-atomic="true"
class={["alert", status]}
aria-label="Alert"
>
<span>{text}</span>
{onClose && (
<button
onClick={handleClose}
aria-label="Close alert"
class="close-button"
>
&times; {/* Close icon */}
</button>
)}
</div>
);
});

0 comments on commit 6f31617

Please sign in to comment.