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

bug: ionic should not re-focus an element when focus already moved on overlay dismiss by developer #28849

Closed
3 tasks done
aeharding opened this issue Jan 18, 2024 · 5 comments · Fixed by #28850
Closed
3 tasks done
Labels
package: core @ionic/core package type: bug a confirmed bug report

Comments

@aeharding
Copy link
Contributor

aeharding commented Jan 18, 2024

Prerequisites

Describe the Feature Request

Allow developer to set custom focus during overlay dismissal.

Describe the Use Case

In the handler of an ion-action-sheet the developer may want to restore focus to a custom element, like a text box.

Describe Preferred Solution

Ionic overlay should detect whether focus has been set by developer, and not restore focus if that is so.

Describe Alternatives

None.

Reproduction

https://github.com/aeharding/test-focus

Additional Information

Not sure if this is considered a feature or a bug 😅

@liamdebeasi
Copy link
Contributor

Thanks, I think this makes sense to have. However, you can provide a reproduction case so I can test your PR?

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Jan 18, 2024
@ionitron-bot ionitron-bot bot removed the triage label Jan 18, 2024
@aeharding
Copy link
Contributor Author

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jan 18, 2024
@liamdebeasi liamdebeasi self-assigned this Feb 7, 2024
@liamdebeasi
Copy link
Contributor

Thanks! This request makes sense. Ionic tries to focus an element inside of the previous view. However, if focus is already in the previous view then we shouldn't attempt to move focus.

@liamdebeasi liamdebeasi changed the title feat: Allow custom focus trap restoration on overlay dismiss bug: ionic should not re-focus an element when focus already moved on overlay dismiss by developer Feb 7, 2024
@liamdebeasi liamdebeasi added package: core @ionic/core package type: bug a confirmed bug report labels Feb 7, 2024
@liamdebeasi liamdebeasi removed their assignment Feb 7, 2024
@ionitron-bot ionitron-bot bot removed triage labels Feb 7, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 13, 2024
…ocus manually (#28850)

Issue number: resolves #28849

---------

## What is the current behavior?

If the developer tries to set focus to a custom element on overlay
dismissal, Ionic will always override that focus.

## What is the new behavior?

- If focus is already set by developer during dismissal, then Ionic will
not restore focus to previous element

## Does this introduce a breaking change?

- [ ] Yes
- [x] No


## Other information

In the before video, you can see the text box is focused by developer
code when "Mention User" is tapped, which opens the keyboard. Shortly
after that, when the bottom sheet fully dismisses, Ionic focuses the
button, removing focus from the text box and hiding the keyboard.

In the after, Ionic detects that the developer has already focused the
text box and does not change that focus.

|Before|After|
|---|---|
|<video
src="https://github.com/ionic-team/ionic-framework/assets/2166114/47d55eff-29af-4019-ac3c-00f9fe722ca7"></video>|
<video
src="https://github.com/ionic-team/ionic-framework/assets/2166114/508ae466-d037-41eb-b518-92338a122b22"></video>|
@liamdebeasi
Copy link
Contributor

This was fixed in #28850. Thanks again for making the PR!

Copy link

ionitron-bot bot commented Mar 14, 2024

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package type: bug a confirmed bug report
Projects
None yet
2 participants