react-key-navigation icon indicating copy to clipboard operation
react-key-navigation copied to clipboard

Need help with focus on the dynamic particular element.

Open pahonski opened this issue 6 years ago • 45 comments

Снимок экрана 2019-03-19 в 10 03 05 How can i put focus on the fourth element in the second vertical list programmatically.

pahonski avatar Mar 19 '19 07:03 pahonski

If you pass forceFocus={true} props to the fourth Focusable element it will be focused when the component mount.

dead avatar Mar 19 '19 12:03 dead

Thank you! But i create the sidebar component when my main component render. I do this because key-navigation doesn't work correct with many dynamic elements. I forced create all my focusable components when my main component render and set for them for example 'display: none'. My component mount 1 time and never unmounted while i am on the main component.

pahonski avatar Mar 20 '19 12:03 pahonski

Just fixed #3. Maybe that will help you.

dead avatar Mar 20 '19 15:03 dead

When i used forseFocus props, it works. Снимок экрана 2019-03-21 в 18 00 22 But when i clicked UP, focus went on the first element, not on the third.

pahonski avatar Mar 21 '19 15:03 pahonski

Sorry, i don't understand how it works.

<VerticalList>
{this.state.dynamicInsert && <Search text="inserted!!" />}
</VerticalList>

In example which i found in the issue#3 it doesn't work.

pahonski avatar Mar 21 '19 16:03 pahonski

Did you update to 0.0.10? The same example in #3 with version 0.0.10 https://codesandbox.io/s/50xy2z3244

<VerticalList>
{this.state.dynamicInsert && <Search text="inserted!!" />}
</VerticalList>

The code above works in version 0.0.9 because the "VerticalList" is already monted, so when the dynamic component is inserted it will be in the correct order/position (the first element of that VerticalList). Same example in #3 using the code above

In version 0.0.10 you don't need VerticalList because it will re-order the children components when the parent component is updated. So just using {this.state.dynamicInsert && <Search text="inserted!!" />} should be fine.

dead avatar Mar 21 '19 16:03 dead

But i need one horizontal list which include 2 vertical lists. The first list for seasons and the second for the series. When i remove Vertical list it doesn't work correct. Снимок экрана 2019-03-21 в 20 25 55

And i get new error with version 0.0.10 when i re-render component withe series. Снимок экрана 2019-03-21 в 20 19 15 Could you tell me what will i need change in my code. I tried to do as you wrote, but it doesn't help me. May be i can't use array with dynamic elements?

pahonski avatar Mar 21 '19 17:03 pahonski

https://youtu.be/bSeYduApEc4 I attached video with problem.

pahonski avatar Mar 21 '19 17:03 pahonski

I think I found out what was your problem, I'm going to fix it soon.

dead avatar Mar 21 '19 20:03 dead

I'm looking forward to fix this problem.

pahonski avatar Mar 22 '19 05:03 pahonski

Please try the v0.0.11

dead avatar Mar 22 '19 13:03 dead

Hello, i have new problem with focusable elements after update. I try to explain it soon. But old problem with correct KEY UP and KEY DOWN isn't fixed.

pahonski avatar Mar 24 '19 07:03 pahonski

https://youtu.be/mCmKylez4s4

Now i can't switch to window with PLAY button when i press KEY_UP. Снимок экрана 2019-03-24 в 10 25 53

This element doesn't dynamic. It has diplay:none. When data are received element is changed display to flex. In the version 0.0.10 it works good, but now it doesn't work.

Main component with navigation: Снимок экрана 2019-03-24 в 10 33 22

Menu component Снимок экрана 2019-03-24 в 10 34 32

ContentList component (films posters). Снимок экрана 2019-03-24 в 10 36 04

I don't know if i explained well. I will record video if you don't understand my problem.

pahonski avatar Mar 24 '19 07:03 pahonski

https://youtu.be/t7VmV8o5dCo

In this video i compare version 9 and 11

pahonski avatar Mar 24 '19 08:03 pahonski

I noticed that the focus is lost when the component is updated. In my case it happened when i get new data from redux. It starts to work incorrectly.

pahonski avatar Mar 25 '19 06:03 pahonski

Thanks for the feedback! But I couldn't reproduce your error... Can you change to mount the component only when it should be visible? That is the only thing that could bug the navigation system because even though it is not visible the navigation is not aware of that. If that is your problem I can create a props disabled that would make the navigation ignore it.

dead avatar Mar 25 '19 12:03 dead

Thank you, this props will be good. On this week i'll try to find, where i get this problem. I'll write about it soon.

pahonski avatar Mar 26 '19 04:03 pahonski

Now i describe other problems, which i noticed.

  1. When my project was downloaded i see some react-dom errors in the console. Without last warning. 1 2
  2. I have search keyboard with focusable buttons, but it doesn't that behaviour which i wanted. https://youtu.be/VAT4_FTInoE

When I focus keyboard and press KEYDOWN i want to go on the second row not ont the menu below. This is the keyboard code: 01

This is the Menu code which include keyboard 02

pahonski avatar Mar 26 '19 07:03 pahonski

  1. Bug with dynamic element when it appears. https://youtu.be/ibXfLau5IL4 this element 6

pahonski avatar Mar 26 '19 07:03 pahonski

I tried dynamical elements in more simple component, but it doesn't work too.

I have Tv component with navigation and other components. 1 Sidebar same as in your example in youtube-tv. 666 List with tv channels which i get from ajax 3 And list items 4

Focus works only on sidebar static element, when i get tv channels list from ajax, they don't get focus. video https://youtu.be/l4VPEaWwYGg

pahonski avatar Mar 26 '19 11:03 pahonski

I added code on the codesandbox.

https://codesandbox.io/s/xlnvr9zr9w

pahonski avatar Mar 26 '19 12:03 pahonski

Update to v.0.0.12 https://codesandbox.io/s/622xk79vvw and now this example work 😄

dead avatar Mar 26 '19 17:03 dead

Hello i noticed another problem. When i render Focusable items as in this example this code works good. 1

But when i render Focusable element in the component as in this example it works one time. Sidebar open and close. But then i don't focus this sidebar. 3

This is component which include focusable. 2

pahonski avatar Mar 27 '19 08:03 pahonski

Can you reproduce this in codesandbox? I tried https://codesandbox.io/s/ryrnxz902n but it works

dead avatar Mar 27 '19 09:03 dead

Maybe this video can help. https://youtu.be/nHktSpwZ168

pahonski avatar Mar 27 '19 09:03 pahonski

I found this bug. https://codesandbox.io/s/72o5yj4mn1

pahonski avatar Mar 27 '19 10:03 pahonski

Can you try the new version (v0.0.13)?

dead avatar Mar 27 '19 12:03 dead

Yes, it's working. Thank you. Did you add props "disabled"? And how can i set navDeafult on the vertical list which include dynamic elements?

pahonski avatar Mar 27 '19 13:03 pahonski

Still haven't added the disabled props. The navDeafult sets the element the navigation will focus when it will lose a focus or the when the navigation start (after loading the page). You want something that when you enter a VerticalList it will focus a specific element?

dead avatar Mar 27 '19 17:03 dead

It would be nice:

  1. when I enter a VerticalList it will focus a specific element.
  2. when i have opportunity to set navDefault on the VerticalList which doesn't has children elements, but it is going to get them from ajax.

pahonski avatar Mar 27 '19 17:03 pahonski