-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[release/1.x] Close dateinput popover #2093
Changes from 2 commits
7f20c79
85bb3d5
031cfdf
4f49526
e6b3f41
9fd606d
76253fe
dafca2c
8745263
69dd5ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,7 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat | |
|
||
private inputRef: HTMLElement = null; | ||
private contentRef: HTMLElement = null; | ||
private lastPopoverElement: HTMLElement = null; | ||
private lastElementInPopover: HTMLElement = null; | ||
|
||
public constructor(props?: IDateInputProps, context?: any) { | ||
super(props, context); | ||
|
@@ -478,8 +478,13 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat | |
this.safeInvokeInputProp("onKeyDown", e); | ||
}; | ||
|
||
// blur DOM event listener (not React event) | ||
private handlePopoverBlur = () => this.handleClosePopover(); | ||
// keyboard DOM event listener (not React event) | ||
private handlePopoverBlur = (e: KeyboardEvent) => { | ||
if (e.which === Keys.TAB && !e.shiftKey) { | ||
e.target.dispatchEvent(new FocusEvent("blur")); | ||
this.handleClosePopover(); | ||
} | ||
}; | ||
|
||
private registerPopoverBlurHandler = () => { | ||
if (this.contentRef != null) { | ||
|
@@ -488,19 +493,23 @@ export class DateInput extends AbstractComponent<IDateInputProps, IDateInputStat | |
const tabbableElements = this.contentRef.querySelectorAll("input, [tabindex]:not([tabindex='-1'])"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to self / @giladgray: we'll need to update this for dom4 v2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is already updated. |
||
const numOfElements = tabbableElements.length; | ||
if (numOfElements > 0) { | ||
const lastPopoverElement = tabbableElements[numOfElements - 1] as HTMLElement; | ||
if (this.lastPopoverElement !== lastPopoverElement) { | ||
// Keep track of the last focusable element in popover and add | ||
// a keydown handler, so that: | ||
// * popover closes when the user tabs to the next element | ||
// * or focus moves to previous element if shift+tab | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something is wrong with the language in this comment. it doesn't parse correctly. i think "popover closes:" belongs after "so that", but then the second bullet sounds incorrect. |
||
const lastElement = tabbableElements[numOfElements - 1] as HTMLElement; | ||
if (this.lastElementInPopover !== lastElement) { | ||
this.unregisterPopoverBlurHandler(); | ||
this.lastPopoverElement = lastPopoverElement; | ||
this.lastPopoverElement.addEventListener("blur", this.handlePopoverBlur); | ||
this.lastElementInPopover = lastElement; | ||
this.lastElementInPopover.addEventListener("keydown", this.handlePopoverBlur); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
private unregisterPopoverBlurHandler = () => { | ||
if (this.lastPopoverElement) { | ||
this.lastPopoverElement.removeEventListener("blur", this.handlePopoverBlur); | ||
if (this.lastElementInPopover != null) { | ||
this.lastElementInPopover.removeEventListener("keydown", this.handlePopoverBlur); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? this is suspicious. we're not in the habit of dispatching DOM events from blueprint code (except where absolutely necessary in tests).