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

allow arrow keys to rotate and pitch the map when focused on the NavigationControl compass button #8953

Closed
wants to merge 4 commits into from

Conversation

andrewharvey
Copy link
Collaborator

Launch Checklist

given you can rotate and pitch with the mouse on the compass button, the same actions should be achievable with the keyboard only.

  • write tests for all new functionality

there were no existing tests for the NavigationControl so I haven't added any, should I go ahead and add some unit tests for the NavigationControl or does this control not need unit tests?

  • document any changes to public APIs
  • manually test the debug page

@@ -102,6 +102,37 @@ class NavigationControl {
this._handler = new DragRotateHandler(map, {button: 'left', element: this._compass});
DOM.addEventListener(this._compass, 'mousedown', this._handler.onMouseDown);
DOM.addEventListener(this._compass, 'touchstart', this._handler.onMouseDown, {passive: false});
DOM.addEventListener(this._compass, 'keydown', (e) => {
const bearingStep = 15,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the implementation here since the zoom in/out button clicks are performed here, and the KeyboardHandler seems focused on handling keyboard events on the map, not the NavigationControl. This does lead to these constants defined twice, is that okay or should they be defined once and them imported into both the KeyboardHandler and NavigationControl?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, which constants are defined twice here?

We don't have a clean separation of focus and input handling, probably KeyboardHandler is a bit misnamed if we have multiple controls that need to handle the keyboard but KeyboardHandler just represents the focused map.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bearingStep and ptichStep are also defined at

bearingStep = 15,
pitchStep = 10;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you. I think it's good to have them defined once and imported. I don't think we'd want to modify these values separately. Maybe it's a good time to start a src/ui/constants.js? I am having a hard time finding other examples in the project of a shared constants file but it seems reasonable to me.

@ahk
Copy link
Contributor

ahk commented Nov 9, 2019

does this control not need unit tests?

Do you have an idea how you would test this? I'd be really appreciative if you drafted some simple ones to get us started. I don't have strong opinions on how to unit test this.

I personally like supporting accessibility features but as with many of our smaller features we're a bit challenged right now adequately retesting these things. Having some basic tests to verify regressions would help a lot with adding more small improvements like this to things that fall outside our main development path.

@andrewharvey
Copy link
Collaborator Author

Do you have an idea how you would test this? I'd be really appreciative if you drafted some simple ones to get us started. I don't have strong opinions on how to unit test this.

invoke the key event and then compare the map rotation and pitch to before the key event was invoked.

I'll do some more work to add in unit tests.

@@ -102,6 +102,37 @@ class NavigationControl {
this._handler = new DragRotateHandler(map, {button: 'left', element: this._compass});
DOM.addEventListener(this._compass, 'mousedown', this._handler.onMouseDown);
DOM.addEventListener(this._compass, 'touchstart', this._handler.onMouseDown, {passive: false});
DOM.addEventListener(this._compass, 'keydown', (e) => {
const bearingStep = 15,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you. I think it's good to have them defined once and imported. I don't think we'd want to modify these values separately. Maybe it's a good time to start a src/ui/constants.js? I am having a hard time finding other examples in the project of a shared constants file but it seems reasonable to me.

@andrewharvey
Copy link
Collaborator Author

So I was part way through implementing unit tests and just saw #9036 which if implemented would nullify this change. So let's hold off for now on this PR until #9036 is resolved.

@andrewharvey
Copy link
Collaborator Author

It might be useful to still keep this functionality even if #9036 goes ahead since shift+arrow is hard to discover, whereas the arrow keys when focused on the compass might be more discoverable? I'm not sure.

@vakila
Copy link

vakila commented Dec 2, 2019

Hi @andrewharvey, first of all thanks for all your work on this - didn't mean to derail it with #9036 but I do think we need to examine whether this functionality is necessary. That said, as I mentioned in #9036 (comment) I'm not sure that implementing #9036 means we shouldn't still consider merging this - I agree with your last comment:

It might be useful to still keep this functionality even if #9036 goes ahead since shift+arrow is hard to discover, whereas the arrow keys when focused on the compass might be more discoverable? I'm not sure.

I'm not sure either - I can see both arguments:

  1. The keyboard controls should have parity with the touch controls, so if we remove the drag-rotate/-pitch compass control then we should not add keyboard-rotate/-pitch controls. (AFAICT clicking the buttons to zoom in/out or reset bearing/pitch is already matched by default behavior of enter/space key when buttons are focused, so we would have parity there without any additional changes.) The fact that we need to reduplicate some of the keyboard handler logic within the NavigationControl here could be an indication that we're trying to cram more functionality into this control than it really should have, given that there are existing mechanisms for manipulating the map without this control.
  2. It might be generally good to give keyboard users more options for how they can control the map, including a modifier-free option by focusing the compass and then using arrows to change bearing/pitch. I'm not entirely sure why, but to me it makes more sense to manipulate the compass button that way (with keyboard) than with the current touch gesture. (But touch users should also have other options, e.g. a touch gesture to control pitch, which we are working on.)

@andrewharvey do you have any feedback/data points from users or other devs that the shift-arrow control is too hard to discover and that focusing the compass and then using arrows would be more user-friendly? That would make sense to me but just based on speculation as I don't really have any data to go off of - wondering if you have data points on that or how we could go about getting some.

I could go either way on this - if we have reason to believe that this will provide the best experience for keyboard-only/keyboard-preferred users, I'm fine with adding this regardless of #9036. Either way, I would love to merge in the test(s) you added, they're sorely needed!

cc @ahk @ryanhamley

@andrewharvey
Copy link
Collaborator Author

didn't mean to derail it with #9036 but I do think we need to examine whether this functionality is necessary.

Oh not at all, I agree that it's important to re-consider if the current UX is worth retaining going forward.

@andrewharvey do you have any feedback/data points from users or other devs that the shift-arrow control is too hard to discover and that focusing the compass and then using arrows would be more user-friendly? That would make sense to me but just based on speculation as I don't really have any data to go off of - wondering if you have data points on that or how we could go about getting some.

Not really, I'm not sure any particular method is better 🤷‍♂️ .

I think this PR is quite low priority so happy to leave it sit here while we see how #9036 pans out, and in case there is any other user feedback.

Either way, I would love to merge in the test(s) you added, they're sorely needed!

The unit tests I did were just for the functionality added in this PR, so no harm done if you're working on some too. I'm not fussed, if you have some ready to ship that's great!

@arindam1993 arindam1993 changed the base branch from master to main June 18, 2020 18:13
@mourner
Copy link
Member

mourner commented Aug 3, 2021

Looks like this is stale — let's close, and possibly reopen when we're ready to work on landing this again.

@mourner mourner closed this Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arrow keys to change bearing when bearing button is active
4 participants