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

Disable the focus trap for report page context menu #15375

Merged
merged 1 commit into from
Feb 24, 2023
Merged
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
14 changes: 14 additions & 0 deletions src/components/PressableWithSecondaryInteraction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class PressableWithSecondaryInteraction extends Component {
if (this.props.preventDefaultContentMenu) {
e.preventDefault();
}

/**
* This component prevents the tapped element from capturing focus.
* We need to blur this element when clicked as it opens modal that implements focus-trapping.
* When the modal is closed it focuses back to the last active element.
* Therefore it shifts the element to bring it back to focus.
* https://github.com/Expensify/App/issues/14148
*/
if (this.props.withoutFocusOnSecondaryInteraction && this.pressableRef) {
this.pressableRef.blur();
}
Comment on lines +45 to +47
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey everyone , this change caused a regression in #17868. In Safari, when copying part of a multiline message, the entire message is copied. The issue was resolved by changing the order from blurring -> onSecondaryInteraction to onSecondaryInteraction -> blurring.

this.props.onSecondaryInteraction(e);
}

Expand All @@ -49,6 +60,9 @@ class PressableWithSecondaryInteraction extends Component {
if (DeviceCapabilities.hasHoverSupport()) {
return;
}
if (this.props.withoutFocusOnSecondaryInteraction && this.pressableRef) {
this.pressableRef.blur();
}
this.props.onSecondaryInteraction(e);
}}
onPressOut={this.props.onPressOut}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const propTypes = {
* Note: Web uses styling instead of Text due to no support of LongPress. Thus above pointers are not valid for web.
*/
inline: PropTypes.bool,

/** Disable focus trap for the element on secondary interaction */
withoutFocusOnSecondaryInteraction: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -39,6 +42,7 @@ const defaultProps = {
onPressOut: () => {},
preventDefaultContentMenu: true,
inline: false,
withoutFocusOnSecondaryInteraction: false,
};

export {propTypes, defaultProps};
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class ReportActionItem extends Component {
onPressOut={() => ControlSelection.unblock()}
onSecondaryInteraction={this.showPopover}
preventDefaultContentMenu={!this.props.draftMessage}
withoutFocusOnSecondaryInteraction
>
<Hoverable>
{hovered => (
Expand Down