jquery element.focus() does not bring element into view




2 years ago
a year ago


(Reporter: soundobj, Unassigned)



45 Branch

Firefox Tracking Flags

(Not tracked)




(1 obsolete attachment)



2 years ago
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Firefox/45.0
Build ID: 20160502160818

Steps to reproduce:

create a <div class="content" tabindex="-1">content goes here</div>
position page so that the div is outside of the viewport

Actual results:

the div is not scrolled into view

Expected results:

the div should be scrolled into view

Comment 1

2 years ago
testing the same behaviour on Firefox version 45.1.1 works ok

Comment 2

2 years ago
Could you attach a testcase to the bug report and test with the latest version, v47., please.
Flags: needinfo?(soundobj)

Comment 3

2 years ago
@loic I have tested with the latest version, hence the issue. I am just noting that reverting to an V45 cures the defect

Comment 4

2 years ago
Created attachment 8761530 [details]

I am unaware of the format for a testcase but here are the steps to reproduce

- create this markup <div class="testcase" tabindex="-1">some content here</div>
on a document
- position the newly created markup outside of the viewport
- programatically execute $(".testcase").viewport
the div is brought into viewport
thie div isn't brought into the viewport

Comment 5

2 years ago
Just attach a testcase, a full webpage in HTML (.html). Or you can use a website like http://codepen.io/ or https://jsfiddle.net/ to share a testcase.
Keywords: testcase-wanted


2 years ago
Attachment #8761530 - Attachment is obsolete: true

Comment 6

2 years ago
@Loic here is the codePen illustrating the issue: http://codepen.io/soundobj/pen/beEvdd

If you try chrome and click the 'bring to view' button it brings the whole div into view.
however if you try firefox it fails to bring the whole div. if you where to add more spacing between the button and the div (add more <br /> and the div is not visible in the viewport) and click 'bring into view' it will bring the whole div into view. so the issue arises when the element is partially visible. note that earlier versions of Firefox was working as expected.
focus() is not a method to bring an element into view. This is what you should use instead:
Last Resolved: 2 years ago
Resolution: --- → INVALID

Comment 8

2 years ago
@Kohei, I appreciate your feedback however there is an issue with using scrollIntoView() instead of $.focus()

- focus() scrolls only what is required to fully display the partially visible element into view; that has a huge impact in usability as the user context in the page remains. 
- scrollIntoView() brings the partially visible element to the top of the page. this has a big usability issue as the user context is greatly changed.

you can also see that if you completely hide the partially visible element need to be brought into view. focus() works fine. it is only when its partially visible that focus() does not work correctly. this was working ok on Firefox version 45.1.1

Looking forward hearing your thoughts.

Comment 9

2 years ago
I have updated the pen with two buttons to illustrate my point you can test in Chrome and Firefox to see the differences, pls make the window the right size as to have the element needed to be focused partially visible.

Kind regards

Comment 10

2 years ago
Where is the new pen?

Comment 12

2 years ago
(In reply to soundobj from comment #9)
> pls make the window the right
> size as to have the element needed to be focused partially visible.
I don't understand what you mean here. Could you explain better to reproduce the issue?

Comment 13

2 years ago
Ok, I tested again after reading again the entire bug report and I'm not able to reproduce:
*.focus(): if the div is partially visible in the viewport, scroll doesn't work. If it's not visible, it scrolls.
*.scrollIntoView(): in both cases, it scrolls.

I tested with FF47 and FF33 on Win 7, same result.
Flags: needinfo?(soundobj)

Comment 14

2 years ago
@Loic Steps to reproduce. 

- enlarge the codepen so the two buttons are visible as well as partially the <div id="content"> so not all the content is visible and its hidden by the bottom end of the container
- click on 'focus' button
- expected: the full div is focused and all its contents are now visible so the hidden part of the div has been scrolled into the viewport.
-actual the div is focused but the hidden content has not been scrolled.

As a comparison when you click on the 'bring to view' button the <div id="content"> is scrolled to the top of the page.

If you try the same in other browsers (chrome or safari) you will see that clicking on 'focus' button scrolls the <div id="content"> so to show just its full content.

Note: this seems to be a regression as this was working ok on Firefox version 45.1.1

Comment 15

2 years ago
Thanks, I got it.

I can't prove it's a regression on Windows, as I said, focus() doesn't scroll to the div with old versions of Firefox like 33.

Boris, as you know DOM and you are on OSX, what do you think?
Component: Untriaged → DOM
Flags: needinfo?(bzbarsky)
Keywords: testcase-wanted → testcase
Product: Firefox → Core
I just tried the codepen in Firefox 45 on Mac.  It has the same behavior as tip when the focus button is clicked: the content is not scrolled.

Note that we should fix bug 1290152 to make it possible to produce the desired behavior with scrollIntoView.

Anyway, nsFocusManager::ScrollIntoView does a ScrollContentIntoView with SCROLL_MINIMUM as the "where to scroll", which should have the desired behavior if the scroll happened.  It also passes SCROLL_IF_NOT_VISIBLE as the "when to scroll".  This bug report seems to be asking for SCROLL_IF_NOT_FULLY_VISIBLE to be passed instead.

I suspect the problem is that using SCROLL_IF_NOT_FULLY_VISIBLE would mess up cases when the thing being focused is too big to fit in the scroll area: it would perform the scroll, and SCROLL_MINIMUM will scroll to top/left if the whole thing doesn't fit.  So it's not clear to me that we have a scroll mode that represents what the reporter is asking for, but I might be missing something....
Flags: needinfo?(bzbarsky) → needinfo?(enndeakin)
I put a testcase for the "thing being focused is larger than the visible area" at http://codepen.io/anon/pen/akKAPK

Comment 18

a year ago
I think whatever flags 'nearest' would use would be correct. SCROLL_IF_NOT_FULLY_VISIBLE isn't correct when only the bottom is visible for example.
Flags: needinfo?(enndeakin)
You need to log in before you can comment on or make changes to this bug.