react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

Unable to scroll first section-header into view using arrow keys

Open tomsontom opened this issue 3 years ago โ€ข 5 comments

๐Ÿ› Bug Report

Once you scroll the first section out view it is impossible to scroll it back into view unless you use the the mouse.

๐Ÿค” Expected Behavior

I would expect that if you scroll the first item in a section into view the header not only the item is scrolled into view but also its section header

๐Ÿ˜ฏ Current Behavior

Impossible to scroll section-header into view. See the following screencast and one can reproduce in the storybook

https://user-images.githubusercontent.com/52631/110013921-79c13f80-7d22-11eb-93ee-c85d236688a6.mp4

๐Ÿ’ Possible Solution

I hacked a bit into Virtualizer.ts

    let x = this.visibleRect.x;
    let y = this.visibleRect.y;
    let minX = layoutInfo.rect.x - offsetX;
    let minY = layoutInfo.rect.y - offsetY;
    if (layoutInfo.parentKey) {
      let parentLayoutInfo = this.layout.getLayoutInfo(layoutInfo.parentKey);
      if (parentLayoutInfo && parentLayoutInfo.rect.y === layoutInfo.rect.y) {
        let headerInfo = this.layout.getLayoutInfo(layoutInfo.parentKey + ':header');
        if (headerInfo) {
          minY = headerInfo.rect.y - offsetY;
        }
      }
    }

where I added the IF-Block, unfortunately one can not access the header-layout-info via API so this feels a bit hacky because I rely on the fact that the header info is stored with the key + ':header' (which is an implementation detail of ListLayout) so ideally one could call an API on Layout to get the information required.

This change does not only scroll the primary section header into view but always the section header if you reach the first item in a section. Another small caveat is that I can not differentiate if you nativate via keys or using the mouse so if you click on the first item in a section and although the item is visible in the view port it still scrolls because the section is not visible

๐Ÿ”ฆ Context

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

Software Version(s)
react-spectrum
Browser
Operating System

๐Ÿงข Your Company/Team

๐Ÿ•ท Tracking Issue (optional)

tomsontom avatar Mar 04 '21 18:03 tomsontom

I confirmed this behavior. @majornista do you have any thoughts on how to improve this behavior with accessibility in mind?

ktabors avatar Mar 10 '21 18:03 ktabors

@ktabors, @tomsontom Scrolling the preceding header into view to ensure that keyboard-only users can access group heading information seems like a reasonable request. Another option, which may have the additional benefit of allowing group headings to be accessed with VoiceOver on iOS, would be to make the headings focusable, like other items in the list. Considering we've had requests to also make disabled items focusable, this may be worth taking up in that context as well.

majornista avatar Mar 17 '21 18:03 majornista

well at least as a none blind user i would not expect that I can traverse to the section/group header when navigating with the arrow up/down. For a blind user it might make sense that he/she can access the section header using CAPSLOCK+ARROW_UP/DOWN (on OS-X - I don't know the Windows keycombo)

tomsontom avatar Mar 18 '21 20:03 tomsontom

We will take some time to explore and do research on possible solutions.

ktabors avatar Mar 19 '21 21:03 ktabors

@ktabors any news on this - If there's a decision what should be done I'd spend some time implementing it.

tomsontom avatar Jul 19 '22 20:07 tomsontom

We'll want to investigate scrolling the section header into view when the user focuses the first item in a section.

LFDanLu avatar Sep 05 '23 20:09 LFDanLu