Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tabs): css changes #2431

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/purple-berries-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@digdir/designsystemet-css": patch
"@digdir/designsystemet-react": patch
---

Tabs: css changes
96 changes: 47 additions & 49 deletions packages/css/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
--dsc-tabs-content-padding: var(--ds-spacing-5);
--dsc-tabs-content-color: var(--ds-color-neutral-text-default);
--dsc-tabs-list-border-color: var(--ds-color-neutral-border-subtle);

&[data-size='sm'] {
--dsc-tabs-tab-padding: var(--ds-spacing-2) var(--ds-spacing-4);
--dsc-tabs-content-padding: var(--ds-spacing-4);
}

&[data-size='lg'] {
--dsc-tabs-tab-padding: var(--ds-spacing-4) var(--ds-spacing-6);
--dsc-tabs-content-padding: var(--ds-spacing-6);
}
}

.ds-tabs__content {
padding: var(--dsc-tabs-content-padding);
color: var(--dsc-tabs-content-color);
}

.ds-tabs__tablist {
display: flex;
flex-direction: row;
border-bottom: var(--ds-border-width-default) solid var(--dsc-tabs-list-border-color);
position: relative;
}

.ds-tabs__tab {
Expand All @@ -23,59 +45,35 @@
color: var(--dsc-tabs-tab-color);
position: relative;
font-family: inherit;
}

.ds-tabs__content {
padding: var(--dsc-tabs-content-padding);
color: var(--dsc-tabs-content-color);
}

.ds-tabs--sm {
--dsc-tabs-tab-padding: var(--ds-spacing-2) var(--ds-spacing-4);
--dsc-tabs-content-padding: var(--ds-spacing-4);
}

.ds-tabs--md {
--dsc-tabs-tab-padding: var(--ds-spacing-3) var(--ds-spacing-5);
--dsc-tabs-content-padding: var(--ds-spacing-5);
}

.ds-tabs--lg {
--dsc-tabs-tab-padding: var(--ds-spacing-4) var(--ds-spacing-6);
--dsc-tabs-content-padding: var(--ds-spacing-6);
}

@media (hover: hover) and (pointer: fine) {
.ds-tabs__tab:hover:not([aria-selected='true']) {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-neutral-border-subtle);
--dsc-tabs-tab-color: var(--ds-color-neutral-text-default);
&[aria-selected='true'] {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-accent-base-default);
--dsc-tabs-tab-color: var(--ds-color-accent-text-subtle);
}
}

.ds-tabs__tab[aria-selected='true'] {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-accent-base-default);
--dsc-tabs-tab-color: var(--ds-color-accent-text-subtle);
}
@composes ds-focus from './utilities.css';

.ds-tabs__tab:focus {
z-index: 2;
}
/* We set z-index to make sure the active line does not bleed over the focus indicator */
&:focus-visible {
Barsnes marked this conversation as resolved.
Show resolved Hide resolved
z-index: 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just do position: relative and also add a comment about why we are doing this? 😊

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need to make sure it lands on top of the other buttons. Using just position relative makes the active line bleed through the focus indicator

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what happens when we use just position: relative:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! comment on z-index and I'm happy <3

}

.ds-tabs__tab::after {
content: '';
display: block;
height: 3px;
width: 100%;
border-radius: var(--dsc-border-radius-full);
background-color: var(--dsc-tabs__tab-bottom-border-color);
position: absolute;
bottom: 0;
left: 0;
}
&::after {
content: '';
display: block;
height: 3px;
width: 100%;
border-radius: var(--dsc-border-radius-full);
background-color: var(--dsc-tabs__tab-bottom-border-color);
position: absolute;
bottom: 0;
left: 0;
}

.ds-tabs__tablist {
display: flex;
flex-direction: row;
border-bottom: var(--ds-border-width-default) solid var(--dsc-tabs-list-border-color);
position: relative;
@media (hover: hover) and (pointer: fine) {
&:hover:not([aria-selected='true']) {
--dsc-tabs__tab-bottom-border-color: var(--ds-color-neutral-border-subtle);
--dsc-tabs-tab-color: var(--ds-color-neutral-text-default);
}
}
}
2 changes: 1 addition & 1 deletion packages/react/src/components/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Tab = forwardRef<HTMLButtonElement, TabProps>((props, ref) => {
<button
{...useTabRest}
type='button'
className={cl('ds-tabs__tab', 'ds-focus', className)}
className={cl('ds-tabs__tab', className)}
ref={ref}
>
{children}
Expand Down
20 changes: 4 additions & 16 deletions packages/react/src/components/Tabs/TabsRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ export const TabsContext = createContext<TabsContextProps>({});
* ```
*/
export const TabsRoot = forwardRef<HTMLDivElement, TabsProps>(
(
{
size = 'md',
children,
value,
defaultValue,
className,
onChange,
...rest
},
ref,
) => {
({ size = 'md', value, defaultValue, className, onChange, ...rest }, ref) => {
const isControlled = value !== undefined;
const [uncontrolledValue, setUncontrolledValue] = useState<
string | undefined
Expand All @@ -77,12 +66,11 @@ export const TabsRoot = forwardRef<HTMLDivElement, TabsProps>(
}}
>
<div
className={cl('ds-tabs', `ds-tabs--${size}`, className)}
className={cl('ds-tabs', className)}
data-size={size}
ref={ref}
{...rest}
>
{children}
</div>
/>
</TabsContext.Provider>
);
},
Expand Down
Loading