Page MenuHomePhabricator

Infusion breaks browser autofocus
Closed, ResolvedPublic

Description

If you built a form (or simply a TextInputElement should work, too, to reproduce this) in PHP and set the autofocus parameter to true, this works without any problems, if you've disabled JavaScript (or don't infuse the element with OO.ui.infuse()). If you infuse an element with an autofocus, the (auto)focus is lost after the element is rebuilt in JS and replaced the original element.

The focus itself should remain on the last autofocused element in the DOM, instead of lost entirely in the form.

This could be more annoying if a user has a slow connection and the browser already focused the autofocused element and OOUI rebuilds it just a second later without to focus it again.

I haven't looked into a solution yet, maybe this is already a known problem and a workaround for it. I just recognized it while working on https://gerrit.wikimedia.org/r/#/c/225842/ :)

Event Timeline

Florian created this task.Jul 20 2015, 5:31 AM
Florian raised the priority of this task from to Needs Triage.
Florian updated the task description. (Show Details)
Florian added a project: OOUI.
Florian added a subscriber: Florian.
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 20 2015, 5:31 AM
matmarex added subscribers: matmarex, cscott.EditedJul 20 2015, 7:34 PM

Yes, it's a known problem, but no, there isn't really a workaround. The autofocus is a special case of the fact that all "dynamic" state of a widget is lost when it is infused – things like focus, value of various form inputs, scroll position, etc. Most of these are only problematic with quick-acting users on slow connections, but broken autofocus is always noticeable.

We'd probably have to give the new widget's constructor access to the original widget's DOM to let it poke at things and try preserving them. Probably won't be very neat, but should be possible.

matmarex claimed this task.Aug 6 2015, 9:36 AM

Change 229684 had a related patch set uploaded (by Bartosz Dziewoński):
Preserve dynamic state of widgets when infusing

https://gerrit.wikimedia.org/r/229684

Jdforrester-WMF moved this task from Backlog to Doing on the OOUI board.Aug 7 2015, 6:22 PM
Jdforrester-WMF triaged this task as Normal priority.Aug 8 2015, 10:12 PM
Jdforrester-WMF set Security to None.
cscott added a comment.EditedAug 8 2015, 10:14 PM

Alternatively, we could just go back to *not* infusing every widget by default, as I've mentioned before. Infusion should be opt-in.

Alternatively, we could just go back to *not* infusing every widget by default, as I've mentioned before. Infusion should be opt-in.

Sure, but that still wouldn't fix T107550 where we do need to infuse anyways.

Jdforrester-WMF closed this task as Resolved.Aug 11 2015, 8:17 PM
Jdforrester-WMF edited projects, added OOjs-UI-next-release; removed Patch-For-Review.

Change 229684 merged by jenkins-bot:
Preserve dynamic state of widgets when infusing

https://gerrit.wikimedia.org/r/229684

Change 231059 had a related patch set uploaded (by Bartosz Dziewoński):
Really preserve dynamic state of widgets when infusing

https://gerrit.wikimedia.org/r/231059

Legoktm reopened this task as Open.Aug 12 2015, 6:03 PM
matmarex raised the priority of this task from Normal to High.Aug 21 2015, 4:24 PM
matmarex lowered the priority of this task from High to Normal.

Change 234737 had a related patch set uploaded (by Bartosz Dziewoński):
Better workaround for infusion autofocus problems (T106313)

https://gerrit.wikimedia.org/r/234737

Change 234737 merged by jenkins-bot:
Better workaround for infusion autofocus problems (T106313)

https://gerrit.wikimedia.org/r/234737

matmarex lowered the priority of this task from Normal to Low.Oct 3 2015, 5:06 PM

Change 231059 merged by jenkins-bot:
Really preserve dynamic state of widgets when infusing

https://gerrit.wikimedia.org/r/231059

Jdforrester-WMF closed this task as Resolved.Feb 9 2016, 7:26 PM
Jdforrester-WMF removed a project: Patch-For-Review.

Change 269837 had a related patch set uploaded (by Bartosz Dziewoński):
Remove workaround for infusion autofocus problems, now fixed!

https://gerrit.wikimedia.org/r/269837

Change 269837 merged by jenkins-bot:
Remove workaround for infusion autofocus problems, now fixed!

https://gerrit.wikimedia.org/r/269837

Change 273224 had a related patch set uploaded (by Thiemo Mättig (WMDE)):
Fix gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273224

Change 273225 had a related patch set uploaded (by Thiemo Mättig (WMDE)):
Fix gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273225

Change 273224 merged by jenkins-bot:
Element: Fix #gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273224

Change 273225 merged by jenkins-bot:
OOjs UI: Fix #gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273225

Change 273250 had a related patch set uploaded (by Jforrester):
OOjs UI: Fix #gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273250

Change 273250 merged by jenkins-bot:
OOjs UI: Fix #gatherPreInfuseState called incorrectly, causing TypeErrors

https://gerrit.wikimedia.org/r/273250