Skip to content

Have optional callback in focusZoneProps to determine if scenario owner wants the input element to lose the focus on arrow key #4290

Merged
dzearing merged 10 commits intomicrosoft:masterfrom
sayali26:sayali/arrowFocusFix
Mar 19, 2018
Merged

Have optional callback in focusZoneProps to determine if scenario owner wants the input element to lose the focus on arrow key #4290
dzearing merged 10 commits intomicrosoft:masterfrom
sayali26:sayali/arrowFocusFix

Conversation

@sayali26
Copy link
Copy Markdown
Collaborator

Description of changes

If the focus zone has specified HandleTabKey = FocusZoneTabbableElements.All then arrowing up and down inside the search box input element does not work (which is expected), But SearchBox can be part of other components such as Context Menu. In this case its very natural for user to press up and down to navigate between the menu items one of them being . Rather than defaulting the behavior for all the scenarios, I am adding an optional callback called as shouldInputLoseFocusOnArrowKey that will be called if it is defined inside function _shouldInputLoseFocus in . If its not specified nothing changes. But if its specified we call it when we have a support for Tabbing specified to a none (undefined) value.

image

@msftclas
Copy link
Copy Markdown

msftclas commented Mar 15, 2018

CLA assistant check
All CLA requirements met.

Copy link
Copy Markdown
Member

@martellaj martellaj left a comment

Choose a reason for hiding this comment

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

Looks good to me. We'll be able to let consumers control which elements give and do not give up focus, without breaking functionality.

/**
* A callback method to determine if the input element should lose focus on arrow keys
* @param {HTMLInputElement} inputElement The input element which is to loose focus.
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add default value down here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

not sure if we could add default value to the callback method. Added @returns

const inputValue = element.value;
const shouldInputLoseFocusOnArrowKey = this.props.shouldInputLoseFocusOnArrowKey
? this.props.shouldInputLoseFocusOnArrowKey(element)
: false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't love that the const shouldInputLoseFocusOnArrowKey is a boolean, but this.props.shouldInputLoseFocusOnArrowKey is a function returning a boolean.

Can we either move this function down to 822, or come up with a different name stating that this is the result of the function?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I have addressed this comment

(selectionStart !== inputValue.length && isForward) ||
!!this.props.handleTabKey) {
(!!this.props.handleTabKey && !(this.props.shouldInputLoseFocusOnArrowKey
&& this.props.shouldInputLoseFocusOnArrowKey(element)))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is it possible to add a unit test to cover this scenario so we don't break it in the future?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(it's super easy, go to the packages/oufr folder, run npm run start-test, edit FocusZone.test.tsx and add a test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I get below error when I run start-test

image

Also what do you mean by packages/oufr folder

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nevermind Joe told me what oufr means :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added test

"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Add shouldInputLoseFocusOnArrowKey callback for scenario to determine if input should loose focus when arrow key is present when Tabbing is enabled on All elements or Input elements",
Copy link
Copy Markdown
Member

@dzearing dzearing Mar 16, 2018

Choose a reason for hiding this comment

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

As a consumer I can't make sense of the reasoning here. Can you fix some of the language? This comment goes into release notes (and it can be markdown, so use backticks around property names.)

FocusZone: adding shouldInputLoseFocusOnArrowKey optional callback for scenarios where the user presses an arrow key on an input element, but we would want to disable moving focus away.

That's just an idea but maybe you could help refine the language.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh good to know. Thanks David. I have updated the change log.

@dzearing dzearing closed this Mar 19, 2018
@dzearing dzearing reopened this Mar 19, 2018
@dzearing dzearing merged commit da374c8 into microsoft:master Mar 19, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants