Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Navigator: add focusTargetSelector to the options
  • Loading branch information
ciampo committed Feb 7, 2022
commit d22645efa519a57af697f9b41f5ba3f9bc69908b
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,25 @@ function NavigatorProvider(

const push: NavigatorContextType[ 'push' ] = useCallback(
( path, options ) => {
// Force the `isBack` flag to `false` when navigating forward on both the
// previous and the new location.
// Also force the `isInitial` flag to `false` for the new location, to make
// sure it doesn't get overridden by mistake.
const { focusTargetSelector, ...restOptions } = options;

// Notes:
// - the `isBack` flag is set to `false` when navigating forwards on both
// the previous and the new location.
// - the `isInitial` flag is set to `false` for the new location, to make
// sure it doesn't get overridden by mistake.
// - the `focusTargetSelector` prop is set on the current (soon previous)
// location, as it is used to restore focus in NavigatorScreen. The
// remaining options are instead set on the new location being pushed.
setLocationHistory( [
...locationHistory.slice( 0, -1 ),
{
...locationHistory[ locationHistory.length - 1 ],
isBack: false,
focusTargetSelector,
},
{
...options,
...restOptions,
path,
isBack: false,
isInitial: false,
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/navigator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*/
import type { ReactNode } from 'react';

type NavigateOptions = {};
type NavigateOptions = {
focusTargetSelector?: string;
};

export type NavigatorLocation = NavigateOptions & {
isInitial?: boolean;
Expand Down