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/menu button #4700

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

kyokaxin
Copy link
Contributor

@kyokaxin kyokaxin commented Jan 8, 2024

close #4592

Copy link
Contributor

@YSMJ1994 YSMJ1994 left a comment

Choose a reason for hiding this comment

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

master有更新,合并后执行下类型检查,根据错误调整下代码吧

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. api的中英文需要参考 docs/index.md 和 docs/index.en-us.md,这不要手动翻译
  2. defaultValue 参考 组件 defaultProps 内定义,不要随便新增或修改
  3. 部分继承自 menu 组件的属性,引用menu 内的定义即可

Copy link
Contributor

Choose a reason for hiding this comment

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

不要修改原来的行为,参考 affix 组件


const refFn = this.props.menuProps.ref;
//@ts-expect-error menuProps 缺少 ref 类型
const refFn = this.props?.menuProps?.ref;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里需要补充 props.menuProps.ref 的类型定义

};

_menuRefHandler = ref => {
this.menu = findDOMNode(ref);
_menuRefHandler = (ref: React.ReactInstance | null | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

ref类型应为 React.ComponentRef<typeof Menu> | null

MenuButton.Item = Menu.Item;
MenuButton.Group = Menu.Group;
MenuButton.Divider = Menu.Divider;
const WithSubMenuButton = MenuButton as typeof MenuButton & {
Copy link
Contributor

Choose a reason for hiding this comment

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

组件定义在index.tsx内就不需要这么做了,直接 static 定义即可


clickMenuItem = (key, ...others) => {
clickMenuItem = (
Copy link
Contributor

Choose a reason for hiding this comment

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

此处不需要独立定义参数类型,直接引用MenuProps['onItemClick']类型即可,参考:
clickMenuItem: MenuProps['onItemClick'] = (keys, ...others) => { ... }

@@ -123,11 +73,20 @@ class MenuButton extends React.Component {

return st;
}
menu: HTMLElement | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

应为 HTMLElement | undefined

Copy link
Contributor

Choose a reason for hiding this comment

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

这里面有不少 any,类型看起来比较简单,最好补充一下

@@ -4,7 +4,7 @@ import { MenuButton } from '@alifd/next';

const { Item, Group, Divider } = MenuButton;

function selectItem(id) {
function selectItem(id: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

作为面向用户的参考示例具有引导作用,需要明确类型

Copy link
Contributor

Choose a reason for hiding this comment

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

anyscripts...

Copy link

你好,该 pr 已 30 天没有活动,因此被标记为 stale,如果之后的 7 天仍然没有活动,该 pr 将被自动关闭

@github-actions github-actions bot added the Stale not active for a lone time label Feb 19, 2024
@eternalsky eternalsky removed the Stale not active for a lone time label Feb 21, 2024
Copy link
Contributor

@YSMJ1994 YSMJ1994 left a comment

Choose a reason for hiding this comment

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

另外合并一下 master吧,合并完了可以本地执行 npm run check menu-button 看自检错误,尽量修复 eslint warning

static getDerivedStateFromProps(props) {
const st = {};
static getDerivedStateFromProps(props: MenuButtonProps) {
const st: MenuButtonProps = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

此处类型应是 Partial<MenuButtonState>

const { selectMode } = this.props;

this.props.onItemClick(key, ...others);
if (typeof this.props.onItemClick === 'function') {
this.props.onItemClick(key, item, event);
Copy link
Contributor

Choose a reason for hiding this comment

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

onItemClick 有在 defaultProps 里设置默认值,这里直接 this.props.onItemClick!(...) 即可

this.props.onItemClick(key, item, event);
}
if (selectMode === 'single') {
this.onPopupVisibleChange(false, 'menuSelect');
Copy link
Contributor

Choose a reason for hiding this comment

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

这里为何要多加一行代码

if (!('selectedKeys' in this.props)) {
this.setState({
selectedKeys: keys,
});
}
this.props.onSelect(keys, ...others);
if (typeof this.props.onSelect === 'function') {
this.props.onSelect(keys, ...others);
Copy link
Contributor

Choose a reason for hiding this comment

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

onItemClick 有默认值,断言即可

this.props.onVisibleChange(visible, type);
if (typeof this.props.onVisibleChange === 'function') {
this.props.onVisibleChange(visible, type);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

onVisibleChange 有设置默认值,这里用 !断言即可

import '../../../demo-helper/style';
import '../../style';

/* eslint-disable */
Copy link
Contributor

Choose a reason for hiding this comment

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

需去除

Copy link
Contributor

Choose a reason for hiding this comment

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

有不少 any,这里面的类型都是比较简单的,最好不要用 any

@eternalsky eternalsky self-requested a review April 17, 2024 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

【Technical upgrade】MenuButton
3 participants