Skip to content
Closed
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
2 changes: 1 addition & 1 deletion packages/ui-components/src/Common/BaseLinkTabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const BaseLinkTabs: FC<LinkTabsProps> = ({
</Component>
))}
</div>

{/* StatelessSelect now handles client-side navigation internally */}
<StatelessSelect
label={label}
className={styles.tabsSelect}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { ChevronDownIcon } from '@heroicons/react/24/solid';
import classNames from 'classnames';
import { useId, useMemo } from 'react';
import { useId, useMemo, useRef, useEffect } from 'react';

import type { SelectGroup, SelectProps } from '#ui/Common/Select';
import type { LinkLike } from '#ui/types';
Expand All @@ -24,9 +25,9 @@ const StatelessSelect = <T extends string>({
className,
ariaLabel,
disabled = false,
as: Component = 'div',
}: StatelessSelectProps<T>) => {
const id = useId();
const detailsRef = useRef<HTMLDetailsElement | null>(null);

const mappedValues = useMemo(() => {
let mappedValues = values;
Expand Down Expand Up @@ -54,6 +55,20 @@ const StatelessSelect = <T extends string>({
[mappedValues, defaultValue]
);

// closing behaviour for outside click
useEffect(() => {
const handleOutside = (e: MouseEvent) => {
if (
detailsRef.current &&
!detailsRef.current.contains(e.target as Node)
) {
detailsRef.current.open = false;
}
};
document.addEventListener('pointerdown', handleOutside);
return () => document.removeEventListener('pointerdown', handleOutside);
}, []);

return (
<div
className={classNames(
Expand All @@ -69,7 +84,7 @@ const StatelessSelect = <T extends string>({
</label>
)}

<details className={styles.trigger} id={id}>
<details className={styles.trigger} id={id} ref={detailsRef}>
<summary
className={styles.summary}
aria-label={ariaLabel}
Expand Down Expand Up @@ -103,18 +118,34 @@ const StatelessSelect = <T extends string>({

{items.map(
({ value, label, iconImage, disabled: itemDisabled }) => (
<Component
<a
key={value}
href={value}
className={classNames(styles.item, styles.text, {
[styles.disabled]: itemDisabled || disabled,
[styles.selected]: value === defaultValue,
})}
aria-disabled={itemDisabled || disabled}
onClick={e => {
// Allow ctrl/cmd/middle click to open new tab
if (e.metaKey || e.ctrlKey || e.button === 1) {
return;
}
e.preventDefault();

if (detailsRef.current) {
detailsRef.current.open = false;
}

// Client-side navigation for internal links
if (typeof window !== 'undefined') {
window.location.href = value;
}
}}
>
{iconImage}
<span>{label}</span>
</Component>
</a>
)
)}
</div>
Expand Down