-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hook useFocusWithin (#804)
- Loading branch information
Showing
14 changed files
with
607 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export class SyntheticFocusEvent<Target = Element> implements React.FocusEvent<Target> { | ||
nativeEvent: FocusEvent; | ||
target: EventTarget & Target; | ||
currentTarget: EventTarget & Target; | ||
relatedTarget: Element; | ||
bubbles: boolean; | ||
cancelable: boolean; | ||
defaultPrevented: boolean; | ||
eventPhase: number; | ||
isTrusted: boolean; | ||
timeStamp: number; | ||
type: string; | ||
|
||
constructor( | ||
type: string, | ||
nativeEvent: FocusEvent, | ||
override: Partial<Pick<FocusEvent, 'target' | 'currentTarget'>> = {}, | ||
) { | ||
this.nativeEvent = nativeEvent; | ||
this.target = (override.target ?? nativeEvent.target) as EventTarget & Target; | ||
this.currentTarget = (override.currentTarget ?? nativeEvent.currentTarget) as EventTarget & | ||
Target; | ||
this.relatedTarget = nativeEvent.relatedTarget as Element; | ||
this.bubbles = nativeEvent.bubbles; | ||
this.cancelable = nativeEvent.cancelable; | ||
this.defaultPrevented = nativeEvent.defaultPrevented; | ||
this.eventPhase = nativeEvent.eventPhase; | ||
this.isTrusted = nativeEvent.isTrusted; | ||
this.timeStamp = nativeEvent.timeStamp; | ||
this.type = type; | ||
} | ||
|
||
isDefaultPrevented(): boolean { | ||
return this.nativeEvent.defaultPrevented; | ||
} | ||
|
||
preventDefault(): void { | ||
this.defaultPrevented = true; | ||
this.nativeEvent.preventDefault(); | ||
} | ||
|
||
stopPropagation(): void { | ||
this.nativeEvent.stopPropagation(); | ||
this.isPropagationStopped = () => true; | ||
} | ||
|
||
isPropagationStopped(): boolean { | ||
return false; | ||
} | ||
|
||
persist() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {useFocusWithin} from './useFocusWithin'; |
Oops, something went wrong.