Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

List Item Steals Focus After Selection #763

Closed
dawsonc623 opened this issue Mar 20, 2019 · 4 comments
Closed

List Item Steals Focus After Selection #763

dawsonc623 opened this issue Mar 20, 2019 · 4 comments
Labels

Comments

@dawsonc623
Copy link

While running through potential use cases for a filtered list component I am working on, I found a strange bug. Rather than explain it, I figured showing it would be better:

https://codesandbox.io/s/32788k0p5q

Follow these steps:

  1. Enter "little" into the text field.
  2. Press tab, then use the down arrow to highlight "Three Little Code Bugs"
  3. Press enter - everything should clear (this is intentional)
  4. Try to enter "little code" into the text field.

You should find once you get "little c" entered "Nine Little Code Bugs" becomes focused, which is in the slot "Three Little Code Bugs" was when it was originally selected. This behaviour persists until the page is refreshed.

I have not dug into why this is happening yet, but once I get a little more time today or tomorrow I will dive into the code and see what I can find. I figured I would submit this in case someone already has an idea of what might be happening or gets to it before I do.

@moog16
Copy link

moog16 commented Mar 21, 2019

@dawsonc623 I think what is happening is the focusListItemAtIndex in the List component remains with the index 2 when it is hidden. You can see the focusListItemAtIndex property in the screenshot below:

Screen Shot 2019-03-21 at 10 42 30 AM

In the MDC Web v1 update, we removed all these state properties on the List component, and are now using the MDC Web foundation. This shouldn't be an issue in the future release. I'll leave this open to revisit when we release that component. You can see it in the branch feat/mdcweb-typescript-update1.

@dawsonc623
Copy link
Author

@moog16 Ah, alright. It is worth noting that in my example code I do try to circumvent the issue by setting selectedIndex to undefined, but that did not make a difference.

I am not sure if the foundation component handles this, but similar to the discussion on this Dialog issue having selectedIndex and handleSelect implies this component should behave as a controlled component. If that is the case, we should think about implementing that behaviour when working on this next.

@moog16
Copy link

moog16 commented Mar 27, 2019

I actually fixed this in the List PR #776. This should be released with the rest of the MDC Web v1 updates.

@moog16
Copy link

moog16 commented May 16, 2019

#776 and v0.12.0 was released. This should no longer be an issue.

@moog16 moog16 closed this as completed May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants