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

fix(modal): do autofocus on content change #2575

Merged
merged 22 commits into from
Jan 16, 2023

Conversation

lubber-de
Copy link
Member

@lubber-de lubber-de commented Nov 27, 2022

Description

The autofocus feature does not work when the content of a modal or flyout is loaded/changed after the modal is shown (and contains an input after the change)

Testcase

The content of the modal changes after 3 seconds (and then has got an input

Broken

Fixed

Closes

#2490

@lubber-de lubber-de added type/bug Any issue which is a bug or PR which fixes a bug lang/javascript Anything involving JavaScript state/awaiting-reviews Pull requests which are waiting for reviews labels Nov 27, 2022
@lubber-de lubber-de added this to the 2.9.1 milestone Nov 27, 2022
@mvorisek
Copy link
Contributor

mvorisek commented Nov 27, 2022

maybe it can be part of refreshInputs, but LGTM

UPDATE: as coded now it will amplify #2476 / #2477 (comment) issues and restore focus on any modal DOM change even if completely unrelated with inputs

I am not sure if it can be fixed easily. IMHO the autoficus on observed change should be set only if:
a) if enabled and no input has focus (as coded now)
b) and the observed (modal) change added a DOM with (visible focusable) input (otherwise there is no point to focus already present input)
c) and the already present (modal) DOM has no (visible focusable) input (otherwise we know autofocus was already done, but user defocused it)

also the #2490 is about tab key trapping, but this PR does not fix it if there is no input in modal to focus

exoego
exoego previously approved these changes Nov 27, 2022
# Conflicts:
#	src/definitions/modules/flyout.js
#	src/definitions/modules/modal.js
exoego
exoego previously approved these changes Dec 17, 2022
@mvorisek
Copy link
Contributor

@lubber-de please see my updated comment, I do not think the current fix is good

there are 2 separate problems:

  1. tab key must be trapped in modal even if there is no input (on show immediately, once only) - [modal] tab key is not trapped on modal open #2490
  2. autoficus on observed change - something that this PR tries to solve - see my previous comment

@lubber-de lubber-de marked this pull request as draft December 17, 2022 22:44
@lubber-de
Copy link
Member Author

lubber-de commented Dec 17, 2022

  1. tab key must be trapped in modal even if there is no input (on show immediately, once only)

I'll do that if autoFocus is true (which it is by default already) otherwise it's a breaking change if we also focus trap when somebody explicitely set autoFocus: false (by whatever reason....)

  1. autofocus on observed change - something that this PR tries to solve - see my previous comment

Yes, understood, i am on it

@lubber-de lubber-de removed the state/awaiting-reviews Pull requests which are waiting for reviews label Dec 19, 2022
@lubber-de lubber-de marked this pull request as ready for review January 14, 2023 23:01
@lubber-de lubber-de added the state/awaiting-reviews Pull requests which are waiting for reviews label Jan 14, 2023
@lubber-de
Copy link
Member Author

I think i covered all mentioned situations now.
@mvorisek If you have time this weekend, i would appreciate, if you can test this

@lubber-de lubber-de merged commit 1373e46 into fomantic:develop Jan 16, 2023
@lubber-de lubber-de deleted the modalautofocusobserve branch January 16, 2023 20:34
@lubber-de lubber-de removed the state/awaiting-reviews Pull requests which are waiting for reviews label Jan 16, 2023
@mvorisek
Copy link
Contributor

I upgraded atk4/ui to Fomantic-UI 2.9.1 and the autofocus is still not fully working, steps to reproduce:

  1. open https://dev.agiletoolkit.org/demos/interactive/modal.php
  2. click Show (first) button
  3. tab key seems to be trapped correctly
  4. hide the modal by clicking on the dimmer
  5. repeat step 2 - open modal again
  6. tab key is not trapped, pressing tab key many times cycle thru the links below the modal

@lubber-de
Copy link
Member Author

I upgraded atk4/ui to Fomantic-UI 2.9.1 and the autofocus is still not fully working, steps to reproduce:

  1. open dev.agiletoolkit.org/demos/interactive/modal.php
  2. click Show (first) button
  3. tab key seems to be trapped correctly
  4. hide the modal by clicking on the dimmer
  5. repeat step 2 - open modal again
  6. tab key is not trapped, pressing tab key many times cycle thru the links below the modal

Should finally be fixed by #2674

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript type/bug Any issue which is a bug or PR which fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants