diff --git a/packages/lib/src/card/Card.tsx b/packages/lib/src/card/Card.tsx index 1723c5b6c..2990318c1 100644 --- a/packages/lib/src/card/Card.tsx +++ b/packages/lib/src/card/Card.tsx @@ -3,12 +3,13 @@ import styled from "@emotion/styled"; import { spaces } from "../common/variables"; import CardPropsType from "./types"; -const Card = styled.div<{ - hasAction: boolean; - margin: CardPropsType["margin"]; - shadowDepth: 0 | 1 | 2; - href?: string; -}>` +const Card = styled.div< + { + hasAction: boolean; + margin: CardPropsType["margin"]; + shadowDepth: 0 | 1 | 2; + } & React.AnchorHTMLAttributes +>` display: flex; cursor: ${({ hasAction }) => (hasAction ? "pointer" : "unset")}; outline: ${({ hasAction }) => !hasAction && "none"}; diff --git a/packages/lib/src/nav-tabs/Tab.tsx b/packages/lib/src/nav-tabs/Tab.tsx index ac262c18c..d61a683c9 100644 --- a/packages/lib/src/nav-tabs/Tab.tsx +++ b/packages/lib/src/nav-tabs/Tab.tsx @@ -13,10 +13,12 @@ const TabContainer = styled.div` flex-direction: column; `; -const TabLink = styled.a<{ - disabled: TabProps["disabled"]; - iconPosition: NavTabsPropsType["iconPosition"]; -}>` +const TabLink = styled.div< + { + disabled: TabProps["disabled"]; + iconPosition: NavTabsPropsType["iconPosition"]; + } & React.AnchorHTMLAttributes +>` box-sizing: border-box; display: flex; flex-direction: ${({ iconPosition }) => (iconPosition === "top" ? "column" : "row")}; @@ -96,11 +98,11 @@ const Tab = forwardRef( notificationNumber = false, ...otherProps }: TabProps, - ref: Ref + ref: Ref ) => { const { iconPosition, tabIndex, focusedLabel } = useContext(NavTabsContext) ?? {}; - const tabRef = useRef(); - const innerRef = useRef(null); + const tabRef = useRef(); + const innerRef = useRef(null); useImperativeHandle(ref, () => innerRef.current!, []); useEffect(() => { @@ -109,7 +111,7 @@ const Tab = forwardRef( } }, [children, focusedLabel]); - const handleOnKeyDown = (event: KeyboardEvent) => { + const handleOnKeyDown = (event: KeyboardEvent) => { switch (event.key) { case " ": case "Enter": @@ -128,11 +130,12 @@ const Tab = forwardRef( aria-disabled={disabled} aria-selected={active} disabled={disabled} + as={href ? "a" : onClick ? "button" : "div"} href={!disabled ? href : undefined} + onClick={!disabled ? onClick : undefined} iconPosition={iconPosition} - onClick={onClick} onKeyDown={handleOnKeyDown} - ref={(anchorRef: HTMLAnchorElement) => { + ref={(anchorRef: HTMLAnchorElement | HTMLDivElement | null) => { tabRef.current = anchorRef; if (ref) { if (typeof ref === "function") ref(anchorRef);