Skip to content

Commit

Permalink
fix(Tabs): active tab has wrong hover style (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsnes authored May 23, 2024
1 parent 10fb504 commit 104e16d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/css/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
}

@media (hover: hover) and (pointer: fine) {
.fds-tabs__tab:hover {
.fds-tabs__tab:hover:not([aria-selected='true']) {
--fds-tabs__tab-bottom-border-color: var(--fds-semantic-border-neutral-subtle);

color: var(--fds-semantic-text-neutral-default);
}
}

.fds-tabs__tab--active {
.fds-tabs__tab[aria-selected='true'] {
--fds-tabs__tab-bottom-border-color: var(--fds-semantic-border-action-default);

color: var(--fds-semantic-text-action-default);
Expand Down
8 changes: 2 additions & 6 deletions packages/react/src/components/Tabs/Tab/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type TabProps = {

export const Tab = forwardRef<HTMLButtonElement, TabProps>((props, ref) => {
const { children, className, ...rest } = props;
const { active, ...useTabRest } = useTabItem(props);
const { ...useTabRest } = useTabItem(props);

return (
<RovingTabindexItem
Expand All @@ -22,11 +22,7 @@ export const Tab = forwardRef<HTMLButtonElement, TabProps>((props, ref) => {
>
<button
{...useTabRest}
className={cl(
'fds-tabs__tab',
active && 'fds-tabs__tab--active',
className,
)}
className={cl('fds-tabs__tab', className)}
ref={ref}
>
{children}
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/components/Tabs/Tab/useTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { TabsContext } from '../Tabs';

import type { TabProps } from './Tab';

type UseTab = (props: TabProps) => {
active: boolean;
} & Pick<
type UseTab = (
props: TabProps,
) => Pick<
HTMLAttributes<HTMLButtonElement>,
'id' | 'aria-selected' | 'role' | 'onClick'
>;
Expand All @@ -16,14 +16,12 @@ type UseTab = (props: TabProps) => {
export const useTabItem: UseTab = (props: TabProps) => {
const { value, ...rest } = props;
const tabs = useContext(TabsContext);
const active = tabs.value == value;
const buttonId = `tab-${useId()}`;

return {
...rest,
active: active,
id: buttonId,
'aria-selected': active,
'aria-selected': tabs.value == value,
role: 'tab',
onClick: () => {
tabs.onChange?.(value);
Expand Down

0 comments on commit 104e16d

Please sign in to comment.