ayanginet commented on a change in pull request #13361:
URL: https://github.com/apache/superset/pull/13361#discussion_r585310779
##########
File path: superset-frontend/src/dashboard/components/menu/WithPopoverMenu.tsx
##########
@@ -17,44 +17,58 @@
* under the License.
*/
import React from 'react';
-import PropTypes from 'prop-types';
import cx from 'classnames';
-const propTypes = {
- children: PropTypes.node,
- disableClick: PropTypes.bool,
- menuItems: PropTypes.arrayOf(PropTypes.node),
- onChangeFocus: PropTypes.func,
- isFocused: PropTypes.bool,
- shouldFocus: PropTypes.func,
- editMode: PropTypes.bool.isRequired,
- style: PropTypes.object,
+type ShouldFocusContainer = HTMLDivElement & {
+ contains: (event_target: EventTarget & HTMLElement) => Boolean;
+}
+
+interface WithPopoverMenuProps {
+ children: React.ReactNode,
+ disableClick: Boolean,
+ menuItems: React.ReactNode[],
+ onChangeFocus: (focus: Boolean) => void,
+ isFocused: Boolean,
+ shouldFocus: (event: any, container: ShouldFocusContainer) => Boolean,
+ editMode: Boolean,
+ style: React.CSSProperties,
};
-const defaultProps = {
- children: null,
- disableClick: false,
- onChangeFocus: null,
- menuItems: [],
- isFocused: false,
- shouldFocus: (event, container) =>
- container?.contains(event.target) ||
- event.target.id === 'menu-item' ||
- event.target.parentNode?.id === 'menu-item',
- style: null,
+interface WithPopoverMenuState {
+ isFocused: Boolean
};
-class WithPopoverMenu extends React.PureComponent {
- constructor(props) {
+
+export default class WithPopoverMenu extends React.PureComponent<
+ WithPopoverMenuProps,
+ WithPopoverMenuState
+ > {
+
+ container: ShouldFocusContainer;
+
+ static defaultProps = {
+ children: null,
+ disableClick: false,
+ onChangeFocus: null,
+ menuItems: [],
+ isFocused: false,
+ shouldFocus: (event: any, container: ShouldFocusContainer) =>
Review comment:
I tried to replace the type of the event from `any` to
`React.FocusEvent<>` so I could have properties like target.
However, if I do so, it raises another issue in handleClick(event). Here,
both events have to be the same type. In handleClick(event) the function calls
document.addEventListener('click', handleClick). addEventListener expects the
following types: `(type: string, listener: EventListenerOrEventListenerObject,
...)`.
So basically, I ended up in a situation when I need to choose one from, but
if I choose one the other breaks.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]