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: Added keyboard navigation to Compose Actions Menu #7846

Merged
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7442217
feat: Add keyboard nav prop
mananjadhav Feb 20, 2022
7b4f2c4
feat: MenuItem focused handling
mananjadhav Feb 20, 2022
04c7aa6
feat: Added keyboard nav handling to BasePopover
mananjadhav Feb 20, 2022
0fff2ee
feat: Force disabled keyboard nav to native popover
mananjadhav Feb 20, 2022
22c2ec4
feat: Added border color focus and nav to compose actions
mananjadhav Feb 20, 2022
8e56bab
feat: Added separate styles for menu Item
mananjadhav Feb 20, 2022
375193f
feat: Reset activeMenuIndex on Popver close
mananjadhav Feb 20, 2022
0832d6b
feat: Removed side borders
mananjadhav Feb 20, 2022
88e3d61
Merge branch 'main' of https://github.com/mananjadhav/App into feat/k…
mananjadhav Feb 24, 2022
2146966
Merge branch 'main' of https://github.com/mananjadhav/App into feat/k…
mananjadhav Mar 21, 2022
fe073c3
fix: removed keyboard flag from native popover
mananjadhav Mar 21, 2022
12f03aa
feat: added transparent border for non focused items
mananjadhav Mar 21, 2022
ba97730
feat: add onFocus to MenuItem Pressable
mananjadhav Mar 21, 2022
7fa16c4
feat: set activeMenuIndex on tab
mananjadhav Mar 21, 2022
652f597
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 18, 2022
6d94373
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 18, 2022
dbb3b5b
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 18, 2022
9bb63a1
Merge branch 'feat/keyboard-navigation-actions-menu' of github.com:ma…
mananjadhav Jul 18, 2022
41d2ddf
fix: rollback basepopover changes
mananjadhav Jul 18, 2022
646e5a0
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 22, 2022
25d6815
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 24, 2022
eed19be
style: indent and space fixes
mananjadhav Jul 24, 2022
b3aec44
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Jul 25, 2022
edac0a4
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Aug 13, 2022
f5a25dc
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Aug 15, 2022
7837375
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Aug 23, 2022
cec8a80
fix: remove unwanted prop
mananjadhav Aug 23, 2022
dd040c0
feat: added ArrowKeyFocusManager for MenuItems
mananjadhav Aug 23, 2022
cc56815
feat: focus when the index match
mananjadhav Aug 23, 2022
3734c99
refactor: remove unused onfocus prop
mananjadhav Aug 23, 2022
4bc3cc2
feat: add enter handler
mananjadhav Aug 23, 2022
ff0a77f
feat: attach listener only to isVisible popup
mananjadhav Aug 23, 2022
abe25ff
fix: reset index on closure and other scenarios
mananjadhav Aug 23, 2022
1f1b042
fix: correct function name
mananjadhav Aug 23, 2022
79e80ea
fix: added method binding
mananjadhav Aug 23, 2022
953fbb0
fix: remove remove key function on modal hide
mananjadhav Aug 23, 2022
52bf456
fix: remove remove key function on modal hide
mananjadhav Aug 23, 2022
d980a5c
Merge branch 'feat/keyboard-navigation-actions-menu' of github.com:ma…
mananjadhav Aug 23, 2022
241e5ff
refactor: remove extra methods
mananjadhav Aug 23, 2022
3bbd0b5
refactor: rename the flag to enable key actions
mananjadhav Aug 23, 2022
2e79205
refactor: moved inline function to class method
mananjadhav Aug 25, 2022
40ea3c9
fix: attach and remove listeners on hide/show
mananjadhav Aug 25, 2022
b6a9503
fix: change maxIndex < 1 check
mananjadhav Aug 25, 2022
332eec0
fix: condition to remove multiple attacher listener
mananjadhav Aug 25, 2022
b77af4c
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Aug 30, 2022
ae0d448
refactor: changed conditions for keyboard listeners
mananjadhav Aug 30, 2022
2d5d8d2
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Sep 3, 2022
8a227c4
refactor: make keyboard actions available by default
mananjadhav Sep 3, 2022
eb15a01
Merge branch 'main' of github.com:mananjadhav/App into feat/keyboard-…
mananjadhav Sep 5, 2022
c446f9d
fix: update threedots menu popover visibility logic
mananjadhav Sep 5, 2022
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
77 changes: 65 additions & 12 deletions src/components/PopoverMenu/BasePopoverMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
propTypes as createMenuPropTypes,
defaultProps as defaultCreateMenuPropTypes,
} from './popoverMenuPropTypes';
import ArrowKeyFocusManager from '../ArrowKeyFocusManager';
import Text from '../Text';
import KeyboardShortcut from '../../libs/KeyboardShortcut';
import CONST from '../../CONST';

const propTypes = {
/** Callback fired when the menu is completely closed */
Expand All @@ -26,13 +29,56 @@ const defaultProps = {
};

class BasePopoverMenu extends PureComponent {
constructor(props) {
super(props);
this.state = {
focusedIndex: -1,
};
this.updateFocusedIndex = this.updateFocusedIndex.bind(this);
}

componentDidMount() {
if (!this.props.shouldEnableArrowKeysActions && !this.props.isVisible) {
return;
}

const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.ENTER;
this.unsubscribeEnterKey = KeyboardShortcut.subscribe(shortcutConfig.shortcutKey, () => {
if (this.state.focusedIndex === -1) {
return;
}
this.props.onItemSelected(this.props.menuItems[this.state.focusedIndex]);
this.updateFocusedIndex(-1); // Reset the focusedIndex on selecting any menu
}, shortcutConfig.descriptionKey, shortcutConfig.modifiers, true);
}
mananjadhav marked this conversation as resolved.
Show resolved Hide resolved

componentWillUnmount() {
if (!this.unsubscribeEnterKey) {
return;
}
this.unsubscribeEnterKey();
}

/**
* @param {Number} index
*/
updateFocusedIndex(index) {
if (!this.props.shouldEnableArrowKeysActions) {
return;
}
this.setState({focusedIndex: index});
}

render() {
return (
<Popover
anchorPosition={this.props.anchorPosition}
onClose={this.props.onClose}
isVisible={this.props.isVisible}
onModalHide={this.props.onMenuHide}
onModalHide={() => {
this.updateFocusedIndex(-1); // Reset the focusedIndex on modal hide
this.props.onMenuHide();
}}
mananjadhav marked this conversation as resolved.
Show resolved Hide resolved
animationIn={this.props.animationIn}
animationOut={this.props.animationOut}
disableAnimation={this.props.disableAnimation}
Expand All @@ -48,17 +94,24 @@ class BasePopoverMenu extends PureComponent {
</Text>
</View>
)}
{_.map(this.props.menuItems, item => (
<MenuItem
key={item.text}
icon={item.icon}
iconWidth={item.iconWidth}
iconHeight={item.iconHeight}
title={item.text}
description={item.description}
onPress={() => this.props.onItemSelected(item)}
/>
))}
<ArrowKeyFocusManager
focusedIndex={this.state.focusedIndex}
maxIndex={this.props.menuItems.length - 1}
onFocusedIndexChanged={this.updateFocusedIndex}
>
{_.map(this.props.menuItems, (item, menuIndex) => (
<MenuItem
key={item.text}
icon={item.icon}
iconWidth={item.iconWidth}
iconHeight={item.iconHeight}
title={item.text}
description={item.description}
onPress={() => this.props.onItemSelected(item)}
focused={this.state.focusedIndex === menuIndex}
mananjadhav marked this conversation as resolved.
Show resolved Hide resolved
/>
))}
</ArrowKeyFocusManager>
</View>
</Popover>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/PopoverMenu/popoverMenuPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ const propTypes = {

/** Whether disable the animations */
disableAnimation: PropTypes.bool,

/** Whether to allow arrow key actions on the list */
shouldEnableArrowKeysActions: PropTypes.bool,
mananjadhav marked this conversation as resolved.
Show resolved Hide resolved
};

const defaultProps = {
animationIn: 'fadeIn',
animationOut: 'fadeOut',
headerText: undefined,
disableAnimation: true,
shouldEnableArrowKeysActions: false,
};

export {propTypes, defaultProps};
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ class ReportActionCompose extends React.Component {
</Tooltip>
</View>
<PopoverMenu
shouldEnableArrowKeysActions
isVisible={this.state.isMenuVisible}
onClose={() => this.setMenuVisibility(false)}
onItemSelected={() => this.setMenuVisibility(false)}
Expand Down