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

refactor(FloatingMenu): rewrite in typescript #18722

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 17 additions & 21 deletions packages/react/src/components/OverflowMenu/OverflowMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/**
* Copyright IBM Corp. 2016, 2023
* Copyright IBM Corp. 2016, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import FloatingMenu, {
import {
DIRECTION_BOTTOM,
DIRECTION_TOP,
FloatingMenu,
type MenuDirection,
type MenuOffset,
} from '../../internal/FloatingMenu';
import React, { ComponentType } from 'react';
import { matches as keyCodeMatches, keys } from '../../internal/keyboard';
Expand Down Expand Up @@ -54,13 +57,12 @@
[DIRECTION_BOTTOM]: -1,
};

/**
* @param {Element} menuBody The menu body with the menu arrow.
* @param {string} direction The floating menu direction.
* @returns {FloatingMenu~offset} The adjustment of the floating menu position, upon the position of the menu arrow.
* @private
*/
export const getMenuOffset = (menuBody, direction, trigger, flip) => {
export const getMenuOffset: MenuOffset = (
menuBody,
direction,
trigger,
flip
) => {
const triggerButtonPositionProp = triggerButtonPositionProps[direction];
const triggerButtonPositionFactor = triggerButtonPositionFactors[direction];
if (__DEV__) {
Expand All @@ -82,17 +84,11 @@
top: 0,
};
}

default:
break;
return { left: 0, top: 0 };

Check warning on line 88 in packages/react/src/components/OverflowMenu/OverflowMenu.tsx

View check run for this annotation

Codecov / codecov/patch

packages/react/src/components/OverflowMenu/OverflowMenu.tsx#L88

Added line #L88 was not covered by tests
}
};

interface Offset {
top?: number | null | undefined;
left?: number | null | undefined;
}

type IconProps = {
className?: string;
'aria-label'?: string;
Expand Down Expand Up @@ -124,7 +120,7 @@
/**
* The menu direction.
*/
direction?: string;
direction?: MenuDirection;

/**
* `true` if the menu alignment should be flipped.
Expand Down Expand Up @@ -160,12 +156,12 @@
/**
* The adjustment in position applied to the floating menu.
*/
menuOffset?: Offset | (() => void);
menuOffset?: MenuOffset;

/**
* The adjustment in position applied to the floating menu.
*/
menuOffsetFlip?: Offset | (() => void);
menuOffsetFlip?: MenuOffset;

/**
* The class to apply to the menu options
Expand Down Expand Up @@ -391,10 +387,10 @@

/**
* The element ref of the tooltip's trigger button.
* @type {React.RefObject<Element>}
* @type {React.RefObject<HTMLElement>}
* @private
*/
_triggerRef = React.createRef();
_triggerRef = React.createRef<HTMLElement>();

componentDidUpdate(_, prevState) {
const { onClose = noopFn } = this.props;
Expand Down
Loading
Loading