Skip to content

Commit

Permalink
feat: pass href to headerLeft function
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 25, 2024
1 parent bee29a9 commit ce6d885
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/elements/src/types.tsx
Expand Up @@ -42,6 +42,7 @@ export type HeaderOptions = {
pressColor?: string;
pressOpacity?: number;
labelVisible?: boolean;
href?: undefined;
}) => React.ReactNode;
/**
* Whether a label is visible in the left button. Used to add extra padding.
Expand Down
4 changes: 4 additions & 0 deletions packages/native-stack/src/types.tsx
Expand Up @@ -123,6 +123,10 @@ export type NativeStackHeaderLeftProps = NativeStackHeaderRightProps & {
* By default, this is only shown on iOS.
*/
label?: string;
/**
* The `href` to use for the anchor tag on web
*/
href?: string;
};

export type NativeStackNavigationOptions = {
Expand Down
2 changes: 2 additions & 0 deletions packages/native-stack/src/views/HeaderConfig.tsx
Expand Up @@ -130,6 +130,8 @@ export function HeaderConfig({
tintColor,
canGoBack,
label: headerBackTitle,
// `href` is only applicable to web
href: undefined,
});
const headerRightElement = headerRight?.({
tintColor,
Expand Down
1 change: 1 addition & 0 deletions packages/native-stack/src/views/NativeStackView.tsx
Expand Up @@ -119,6 +119,7 @@ export function NativeStackView({ state, descriptors }: Props) {
tintColor,
canGoBack,
label: headerBackTitle,
href: headerBack?.href,
})
: headerLeft === undefined && canGoBack
? ({ tintColor }) => (
Expand Down
4 changes: 4 additions & 0 deletions packages/stack/src/types.tsx
Expand Up @@ -264,6 +264,10 @@ export type StackHeaderRightProps = {
};

export type StackHeaderLeftProps = HeaderBackButtonProps & {
/**
* The `href` to use for the anchor tag on web
*/
href?: string;
/**
* Whether it's possible to navigate back in stack.
*/
Expand Down
5 changes: 2 additions & 3 deletions packages/stack/src/views/Header/HeaderSegment.tsx
Expand Up @@ -109,9 +109,7 @@ export function HeaderSegment(props: Props) {
backHref,
headerTitle: title,
headerLeft: left = onGoBack
? (props: HeaderBackButtonProps) => (
<HeaderBackButton {...props} href={backHref} />
)
? (props: HeaderBackButtonProps) => <HeaderBackButton {...props} />
: undefined,
headerRight: right,
headerBackImage,
Expand Down Expand Up @@ -162,6 +160,7 @@ export function HeaderSegment(props: Props) {
? (props) =>
left({
...props,
href: backHref,
backImage: headerBackImage,
accessibilityLabel: headerBackAccessibilityLabel,
testID: headerBackTestID,
Expand Down

0 comments on commit ce6d885

Please sign in to comment.