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
base: master
Are you sure you want to change the base?
Feat/menu button #4700
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
master有更新,合并后执行下类型检查,根据错误调整下代码吧
components/menu-button/types.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- api的中英文需要参考 docs/index.md 和 docs/index.en-us.md,这不要手动翻译
- defaultValue 参考 组件 defaultProps 内定义,不要随便新增或修改
- 部分继承自 menu 组件的属性,引用menu 内的定义即可
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要补充 props.menuProps.ref 的类型定义
components/menu-button/index.tsx
Outdated
}; | ||
|
||
_menuRefHandler = ref => { | ||
this.menu = findDOMNode(ref); | ||
_menuRefHandler = (ref: React.ReactInstance | null | undefined) => { |
There was a problem hiding this comment.
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
components/menu-button/index.tsx
Outdated
MenuButton.Item = Menu.Item; | ||
MenuButton.Group = Menu.Group; | ||
MenuButton.Divider = Menu.Divider; | ||
const WithSubMenuButton = MenuButton as typeof MenuButton & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
组件定义在index.tsx内就不需要这么做了,直接 static 定义即可
components/menu-button/index.tsx
Outdated
|
||
clickMenuItem = (key, ...others) => { | ||
clickMenuItem = ( |
There was a problem hiding this comment.
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) => { ... }
components/menu-button/index.tsx
Outdated
@@ -123,11 +73,20 @@ class MenuButton extends React.Component { | |||
|
|||
return st; | |||
} | |||
menu: HTMLElement | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应为 HTMLElement | undefined
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
作为面向用户的参考示例具有引导作用,需要明确类型
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anyscripts...
你好,该 pr 已 30 天没有活动,因此被标记为 stale,如果之后的 7 天仍然没有活动,该 pr 将被自动关闭 |
There was a problem hiding this 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 = {}; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需去除
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有不少 any,这里面的类型都是比较简单的,最好不要用 any
close #4592