Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -804,16 +804,23 @@ export class FocusZone extends BaseComponent<IFocusZoneProps, {}> implements IFo
const selectionEnd = element.selectionEnd;
const isRangeSelected = selectionStart !== selectionEnd;
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


// We shouldn't lose focus in the following cases:
// 1. There is range selected.
// 2. When selection start is larger than 0 and it is backward.
// 3. when selection start is not the end of lenght and it is forward.
// 3. when selection start is not the end of length and it is forward.
// 4. We press any of the arrow keys when our handleTabKey isn't none or undefined (only losing focus if we hit tab)
if (isRangeSelected ||
// and if shouldInputLoseFocusOnArrowKey is defined, if scenario prefers to not loose the focus which is determined by calling the
// callback shouldInputLoseFocusOnArrowKey
if (
isRangeSelected ||
(selectionStart > 0 && !isForward) ||
(selectionStart !== inputValue.length && isForward) ||
!!this.props.handleTabKey) {
(!!this.props.handleTabKey && !shouldInputLoseFocusOnArrowKey)
) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export interface IFocusZoneProps extends React.HTMLAttributes<HTMLElement | Focu
*/
handleTabKey?: FocusZoneTabbableElements;

/**
* 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

shouldInputLoseFocusOnArrowKey?: (inputElement: HTMLInputElement) => boolean;

/**
* Whether the to check for data-no-horizontal-wrap or data-no-vertical-wrap attributes
* when determining how to move focus
Expand Down