Skip to content

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinLeCaignec committed Oct 17, 2023
1 parent 62c45a6 commit 500a324
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export function DropdownButton(props: IDropdownButtonProps): ReactElement {
{...menuProps}
>
<Menu.Target>
{buttonComponent ? (
buttonComponent
) : (
{buttonComponent ?? (
<Button
data-testid="button"
rightIcon={opened ? <CaretUp /> : <CaretDown />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const useStyles = createStyles((theme) => ({
},
}));

const dropdownButtonWidth = 30;

export interface IResponsiveTabs extends TabsProps {
children: ReactNode;
dropdownButtonProps?: IDropdownButtonProps;
Expand All @@ -101,11 +103,12 @@ export function ResponsiveTabs(props: IResponsiveTabs): ReactNode {
useLayoutEffect(() => {
const tabElements = Array.from(ref.current.children) as HTMLElement[];
const index = tabElements.findIndex(
// calculate which elements overflow out of parent width, include width of potential dropdown button in the calculation except on last element
(el, i) =>
el.id !== overflowButtonId &&
el.offsetLeft +
el.offsetWidth +
(i === tabElements.length - 1 ? 0 : 30) >
(i === tabElements.length - 1 ? 0 : dropdownButtonWidth) >
width,
);
setOverflowIndex(index !== -1 ? index : tabs.length);
Expand All @@ -132,6 +135,7 @@ export function ResponsiveTabs(props: IResponsiveTabs): ReactNode {
}
classNames={{ dropdown: classes.dropdown }}
id={overflowButtonId}
keepMounted
offset={4}
position="bottom-end"
{...dropdownButtonProps}
Expand Down

0 comments on commit 500a324

Please sign in to comment.