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

✨Autofocus on show() #20687

Merged
merged 9 commits into from
Feb 6, 2019
Merged

✨Autofocus on show() #20687

merged 9 commits into from
Feb 6, 2019

Conversation

alanorozco
Copy link
Member

@alanorozco alanorozco commented Feb 5, 2019

Breakdown

  • Autofocuses element annotated as [autofocus] inside the displayed tree via show/toggle.
  • Forces synchronous display-focus chain on iOS so that programmatic focus is actually honored.

Usage

  <button on="tap: wrapper.show">
    Show
  </button>
  <div id="wrapper" hidden>
    <input type="text" autofocus>
  </div>

etc.

Demo: https://amp-autofocus.glitch.me/

Closes #19949.

@alanorozco alanorozco requested a review from aghassemi February 5, 2019 19:28
const autofocusElOrNull = getAutofocusElementForShowAction(target);

// Safari only honors focus in sync operations.
if (autofocusElOrNull && Services.platformFor(ownerWindow).isSafari()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Check for iOS instead, it is an iOS thing (I don't think isSafari catches Chrome on iOS for example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, fixed. PTAL.

@alanorozco alanorozco self-assigned this Feb 6, 2019
@alanorozco alanorozco merged commit a398c39 into ampproject:master Feb 6, 2019
@alanorozco alanorozco deleted the autofocus branch February 6, 2019 02:41
nbeloglazov pushed a commit to nbeloglazov/amphtml that referenced this pull request Feb 12, 2019
## Breakdown

- Autofocuses optional `[autofocus]` element in the displayed tree via `show`/`toggle`.
- Forces synchronous display-focus chain on iOS so that programmatic focus is honored.

## Usage

```html
  <button on="tap: wrapper.show">
    Show
  </button>
  <div id="wrapper" hidden>
    <input type="text" autofocus>
  </div>
```

## etc.

Demo: <https://amp-autofocus.glitch.me/>

Closes ampproject#19949.
noranazmy pushed a commit to noranazmy/amphtml that referenced this pull request Mar 22, 2019
## Breakdown

- Autofocuses optional `[autofocus]` element in the displayed tree via `show`/`toggle`.
- Forces synchronous display-focus chain on iOS so that programmatic focus is honored.

## Usage

```html
  <button on="tap: wrapper.show">
    Show
  </button>
  <div id="wrapper" hidden>
    <input type="text" autofocus>
  </div>
```

## etc.

Demo: <https://amp-autofocus.glitch.me/>

Closes ampproject#19949.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants