Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop to disable active index change on up / down keys #635

Open
learningdesignlabs opened this issue Apr 9, 2021 · 3 comments
Open

Prop to disable active index change on up / down keys #635

learningdesignlabs opened this issue Apr 9, 2021 · 3 comments

Comments

@learningdesignlabs
Copy link

Perusing the existing issues, I can see that active index is meant to be internal.

However, I believe there's a use case for being able to set it as a prop: when the options are sequential (as in a list of available times to choose from), and if we want behavior similar to how Google calendar events work, where adjacent options should still be displayed, we'd want to have the current option highlighted and selectable from pressing Enter:

Sample select behavior for sequential choices

Additionally, if we want the option of pressing up/down and moving from our current time to a new one, at the moment, even a custom menu and menu item render won't allow this behavior, because the current UP / DOWN behavior is part of the source code and always starts from the very first item of the list.

As I understand, if I could pass a function that specifies the active index, then I could base the active index off of the current selected value. Or, perhaps there is a way to expose the "_handleActiveIndexChange" function?

@learningdesignlabs
Copy link
Author

learningdesignlabs commented Apr 20, 2021

So, looks like I was able to make due simply by disabling the up / down behavior and handling those key events on my own. However, I had to modify the source, to disable the default up / down behavior. It also seems that no other area of code was affected...

May I request just a simple disabling of this option, based on a 'enableDefaultUpDownSelection'={true | false} prop?

switch (e.keyCode) {
          case UP:
          case DOWN:
            // Prevent input cursor from going to the beginning when pressing up.
            e.preventDefault();

            // I JUST HAD TO COMMENT OUT THIS ONE LINE AND COULD GET THINGS TO WORK JUST FINE:
            //
            //_this._handleActiveIndexChange(getUpdatedActiveIndex(_this.state.activeIndex, e.keyCode, _this.items));

@learningdesignlabs learningdesignlabs changed the title Programmatically control active index Prop to disable active index change on up / down keys Apr 20, 2021
@ericgio
Copy link
Owner

ericgio commented Apr 22, 2021

Hi @learningdesignlabs, thanks for opening this issue! It sounds like the behavior you'd like is for the activeIndex to default to the selected item (if it exists), similar to a standard select component, is that right?

@learningdesignlabs
Copy link
Author

Hi Ericgio, thanks so much for the response, I would say allowing activeIndex to default to the selected item would be a great feature, but in this use case there is some additional custom behavior beyond the current item being selected..

For example, in Google calendar if the value is 2:43pm, it will scroll the user down to 2:45pm, without highlighting it.. in which case, activeIndex isn't set, but the scroll position has changed.

In short, from my point of view being allowed to completely control behavior on Up / Down (vs having the system modify activeIndex, and also running my custom code via the onKeyDown prop), by disabling that line of code I mentioned above, would really solve this use case without too much rework..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants