mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 10:41:13 +08:00
fix(react): IonNav apply properties to page components (#25603)
Resolves #25602
This commit is contained in:
@ -4,27 +4,34 @@ import React, { useState } from 'react';
|
||||
|
||||
import { ReactDelegate } from '../../framework-delegate';
|
||||
import { createReactComponent } from '../react-component-lib';
|
||||
import { createForwardRef } from '../utils';
|
||||
|
||||
const IonNavInner = createReactComponent<
|
||||
JSX.IonNav & { delegate: FrameworkDelegate },
|
||||
HTMLIonNavElement
|
||||
>('ion-nav', undefined, undefined, defineCustomElement);
|
||||
|
||||
export const IonNav: React.FC<JSX.IonNav> = ({ children, ...restOfProps }) => {
|
||||
const [views, setViews] = useState<React.ReactPortal[]>([]);
|
||||
type IonNavProps = JSX.IonNav & {
|
||||
forwardedRef?: React.ForwardedRef<HTMLIonNavElement>;
|
||||
};
|
||||
|
||||
const IonNavInternal: React.FC<IonNavProps> = ({ children, forwardedRef, ...restOfProps }) => {
|
||||
const [views, setViews] = useState<React.ReactElement[]>([]);
|
||||
|
||||
/**
|
||||
* Allows us to create React components that are rendered within
|
||||
* the context of the IonNav component.
|
||||
*/
|
||||
const addView = (view: React.ReactPortal) => setViews([...views, view]);
|
||||
const removeView = (view: React.ReactPortal) => setViews(views.filter((v) => v !== view));
|
||||
const addView = (view: React.ReactElement) => setViews([...views, view]);
|
||||
const removeView = (view: React.ReactElement) => setViews(views.filter((v) => v !== view));
|
||||
|
||||
const delegate = ReactDelegate(addView, removeView);
|
||||
|
||||
return (
|
||||
<IonNavInner delegate={delegate} {...restOfProps}>
|
||||
<IonNavInner delegate={delegate} ref={forwardedRef} {...restOfProps}>
|
||||
{views}
|
||||
</IonNavInner>
|
||||
);
|
||||
};
|
||||
|
||||
export const IonNav = createForwardRef<IonNavProps, HTMLIonNavElement>(IonNavInternal, 'IonNav');
|
||||
|
Reference in New Issue
Block a user