Skip to content

Commit

Permalink
fix(react): defaultHref fixes (ionic-team#18278)
Browse files Browse the repository at this point in the history
* fix(react): making children prop optional on overlay components

* fix(react): passing in defaultHref so it can be used if there is no prev view
  • Loading branch information
elylucas authored and kiku-jw committed May 16, 2019
1 parent b2b1b65 commit 41a6260
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions react/src/components/createControllerComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export function createControllerComponent<T extends object, E extends OverlayCom
const displayName = dashToPascalCase(tagName);
const dismissEventName = `on${displayName}DidDismiss`;

type ReactProps = {
type ReactControllerProps = {
isOpen: boolean;
onDidDismiss: (event: CustomEvent<OverlayEventDetail>) => void;
}
type Props = T & ReactProps;
type Props = T & ReactControllerProps;

return class ReactControllerComponent extends React.Component<Props> {
element: E;
Expand Down
8 changes: 4 additions & 4 deletions react/src/components/createOverlayComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export function createOverlayComponent<T extends object, E extends OverlayCompon
const displayName = dashToPascalCase(tagName);
const dismissEventName = `on${displayName}DidDismiss`;

type ReactProps = {
children: React.ReactNode;
type ReactOverlayProps = {
children?: React.ReactNode;
isOpen: boolean;
onDidDismiss: (event: CustomEvent<OverlayEventDetail>) => void;
}
type Props = T & ReactProps;
type Props = T & ReactOverlayProps;

return class ReactControllerComponent extends React.Component<Props> {
return class ReactOverlayComponent extends React.Component<Props> {
element: E;
controllerElement: C;
el: HTMLDivElement;
Expand Down
11 changes: 5 additions & 6 deletions react/src/components/navigation/IonRouterOutlet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface State {
}

interface ContextInterface {
goBack: () => void
goBack: (defaultHref?: string) => void
}

const Context = React.createContext<ContextInterface>({
Expand Down Expand Up @@ -152,11 +152,11 @@ class RouterOutlet extends Component<Props, State> {
});
}

goBack = () => {
goBack = (defaultHref?: string) => {
const prevView = this.state.views.find(v => v.id === this.state.activeId);
const newView = this.state.views.find(v => v.id === prevView.prevId);

this.props.history.replace(newView.location.pathname);
const newPath = newView ? newView.location.pathname : defaultHref;
this.props.history.replace(newPath);
}

componentDidUpdate() {
Expand Down Expand Up @@ -232,8 +232,7 @@ export class IonBackButton extends Component<ButtonProps> {

clickButton = (e: MouseEvent) => {
e.stopPropagation();

this.context.goBack();
this.context.goBack(this.props.defaultHref);
}

render() {
Expand Down

0 comments on commit 41a6260

Please sign in to comment.