Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ yarn-debug.log*
yarn-error.log*

static/**/node_modules/
.idea
1 change: 1 addition & 0 deletions cspell-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Udemy
Vetur
Wistia
WCAG
CDK

actionsheet
fabs
Expand Down
213 changes: 213 additions & 0 deletions docs/angular/overlays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
title: Overlay Components
sidebar_label: Overlays
---

<head>
<title>Angular Overlay Components: Modals, Popovers with Custom Injectors</title>
<meta
name="description"
content="Learn how to use overlay components like modals and popovers in Ionic Angular, including passing custom injectors for dependency injection."
/>
</head>

Ionic provides overlay components such as modals and popovers that display content on top of your application. In Angular, these overlays can be created using controllers like `ModalController` and `PopoverController`.

## Creating Overlays

Overlays can be created programmatically using their respective controllers:

```typescript
import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular/standalone';
import { MyModalComponent } from './my-modal.component';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
})
export class HomeComponent {
constructor(private modalController: ModalController) {}

async openModal() {
const modal = await this.modalController.create({
component: MyModalComponent,
componentProps: {
title: 'My Modal',
},
});
await modal.present();
}
}
```

## Custom Injectors

By default, overlay components use the root injector for dependency injection. This means that services or tokens provided at the route level or within a specific component tree are not accessible inside the overlay.

The `injector` option allows you to pass a custom Angular `Injector` when creating a modal or popover. This enables overlay components to access services and tokens that are not available in the root injector.

### Use Cases

Custom injectors are useful when you need to:

- Access route-scoped services from within an overlay
- Use Angular CDK's `Dir` directive for bidirectional text support
- Access any providers that are not registered at the root level

### Usage

To use a custom injector, pass it to the `create()` method:

```typescript
import { Component, Injector } from '@angular/core';
import { ModalController } from '@ionic/angular/standalone';
import { MyModalComponent } from './my-modal.component';
import { MyRouteService } from './my-route.service';

@Component({
selector: 'app-feature',
templateUrl: './feature.component.html',
providers: [MyRouteService], // Service provided at route level
})
export class FeatureComponent {
constructor(private modalController: ModalController, private injector: Injector) {}

async openModal() {
const modal = await this.modalController.create({
component: MyModalComponent,
injector: this.injector, // Pass the component's injector
});
await modal.present();
}
}
```

The modal component can now inject `MyRouteService`:

```typescript
import { Component, inject } from '@angular/core';
import { MyRouteService } from '../my-route.service';

@Component({
selector: 'app-my-modal',
templateUrl: './my-modal.component.html',
})
export class MyModalComponent {
private myRouteService = inject(MyRouteService);
}
```

### Creating a Custom Injector

You can also create a custom injector with specific providers:

```typescript
import { Component, Injector } from '@angular/core';
import { ModalController } from '@ionic/angular/standalone';
import { MyModalComponent } from './my-modal.component';
import { MyService } from './my.service';

@Component({
selector: 'app-feature',
templateUrl: './feature.component.html',
})
export class FeatureComponent {
constructor(private modalController: ModalController, private injector: Injector) {}

async openModal() {
const myService = new MyService();
myService.configure({ someOption: true });

const customInjector = Injector.create({
providers: [{ provide: MyService, useValue: myService }],
parent: this.injector,
});

const modal = await this.modalController.create({
component: MyModalComponent,
injector: customInjector,
});
await modal.present();
}
}
```

### Using with Angular CDK Directionality

A common use case is providing the Angular CDK `Dir` directive to overlays for bidirectional text support:

```typescript
import { Component, Injector } from '@angular/core';
import { Dir } from '@angular/cdk/bidi';
import { ModalController } from '@ionic/angular/standalone';
import { MyModalComponent } from './my-modal.component';

@Component({
selector: 'app-feature',
templateUrl: './feature.component.html',
})
export class FeatureComponent {
constructor(private modalController: ModalController, private injector: Injector) {}

async openModal() {
const modal = await this.modalController.create({
component: MyModalComponent,
injector: this.injector, // Includes Dir from component tree
});
await modal.present();
}
}
```

### Popover Controller

The `PopoverController` supports the same `injector` option:

```typescript
import { Component, Injector } from '@angular/core';
import { PopoverController } from '@ionic/angular/standalone';
import { MyPopoverComponent } from './my-popover.component';

@Component({
selector: 'app-feature',
templateUrl: './feature.component.html',
})
export class FeatureComponent {
constructor(private popoverController: PopoverController, private injector: Injector) {}

async openPopover(event: Event) {
const popover = await this.popoverController.create({
component: MyPopoverComponent,
event: event,
injector: this.injector,
});
await popover.present();
}
}
```

## Angular Options Types

Ionic Angular exports its own `ModalOptions` and `PopoverOptions` types that extend the core options with Angular-specific properties like `injector`:

- `ModalOptions` - Extends core `ModalOptions` with the `injector` property
- `PopoverOptions` - Extends core `PopoverOptions` with the `injector` property

These types are exported from `@ionic/angular` and `@ionic/angular/standalone`:

```typescript
import type { ModalOptions, PopoverOptions } from '@ionic/angular/standalone';
```

## Docs for Overlays in Ionic

For full docs and to see usage examples, visit the docs page for each of the overlays in Ionic:

- [Action Sheet](https://ionicframework.com/docs/api/action-sheet)
- [Alert](https://ionicframework.com/docs/api/alert)
- [Loading](https://ionicframework.com/docs/api/loading)
- [Modal](https://ionicframework.com/docs/api/modal)
- [Picker](https://ionicframework.com/docs/api/picker)
- [Popover](https://ionicframework.com/docs/api/popover)
- [Toast](https://ionicframework.com/docs/api/toast)
11 changes: 11 additions & 0 deletions docs/api/datetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import MultipleDateSelection from '@site/static/usage/v8/datetime/multiple/index
import GlobalTheming from '@site/static/usage/v8/datetime/styling/global-theming/index.md';
import CalendarHeaderStyling from '@site/static/usage/v8/datetime/styling/calendar-header/index.md';
import CalendarDaysStyling from '@site/static/usage/v8/datetime/styling/calendar-days/index.md';
import DatetimeHeaderStyling from '@site/static/usage/v8/datetime/styling/datetime-header/index.md';
import WheelStyling from '@site/static/usage/v8/datetime/styling/wheel-styling/index.md';

<head>
Expand Down Expand Up @@ -353,6 +354,16 @@ The benefit of this approach is that every component, not just `ion-datetime`, c

<GlobalTheming />

### Datetime Header

The datetime header manages the content for the `title` slot and the selected date.

:::note
The selected date will not render if `preferWheel` is set to `true`.
:::

<DatetimeHeaderStyling />

### Calender Header

The calendar header manages the date navigation controls (month/year picker and prev/next buttons) and the days of the week when using a grid style layout.
Expand Down
73 changes: 73 additions & 0 deletions docs/api/modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ A few things to keep in mind when creating custom dialogs:
* `ion-content` is intended to be used in full-page modals, cards, and sheets. If your custom dialog has a dynamic or unknown size, `ion-content` should not be used.
* Creating custom dialogs provides a way of ejecting from the default modal experience. As a result, custom dialogs should not be used with card or sheet modals.

## Event Handling

### Using `ionDragStart` and `ionDragEnd`

The `ionDragStart` event is emitted as soon as the user begins a dragging gesture on the modal. This event fires at the moment the user initiates contact with the handle or modal surface, before any actual displacement occurs. It is particularly useful for preparing the interface for a transition, such as hiding certain interactive elements (like headers or buttons) to ensure a smooth dragging experience.

The `ionDragEnd` event is emitted when the user completes the dragging gesture by releasing the modal. Like the move event, it includes the final [`ModalDragEventDetail`](#modaldrageventdetail) object. This event is commonly used to finalize state changes once the modal has come to a rest.

import DragStartEndEvents from '@site/static/usage/v8/modal/drag-start-end-events/index.md';

<DragStartEndEvents />

### Using `ionDragMove`

The `ionDragMove` event is emitted continuously while the user is actively dragging the modal. This event provides a [`ModalDragEventDetail`](#modaldrageventdetail) object containing real-time data, essential for creating highly responsive UI updates that react instantly to the user's touch. For example, the `progress` value can be used to dynamically darken a header's opacity as the modal is dragged upward.

import DragMoveEvent from '@site/static/usage/v8/modal/drag-move-event/index.md';

<DragMoveEvent />

## Interfaces

### ModalOptions
Expand Down Expand Up @@ -251,6 +271,59 @@ interface ModalCustomEvent extends CustomEvent {
}
```

### ModalDragEventDetail

When using the `ionDragMove` and `ionDragEnd` events, the event detail contains the following properties:

```typescript
interface ModalDragEventDetail {
/**
* The current Y position of the modal.
*
* This can be used to determine how far the modal has been dragged.
*/
currentY: number;
/**
* The change in Y position since the gesture started.
*
* This can be used to determine the direction of the drag.
*/
deltaY: number;
/**
* The velocity of the drag in the Y direction.
*
* This can be used to determine how fast the modal is being dragged.
*/
velocityY: number;
/**
* A number between 0 and 1.
*
* In a sheet modal, progress represents the relative position between
* the lowest and highest defined breakpoints.
*
* In a card modal, it measures the relative position between the
* bottom of the screen and the top of the modal when it is fully
* open.
*
* This can be used to style content based on how far the modal has
* been dragged.
*/
progress: number;
/**
* If the modal is a sheet modal, this will be the breakpoint that
* the modal will snap to if the user lets go of the modal at the
* current moment.
*
* If it's a card modal, this property will not be included in the
* event payload.
*
* This can be used to style content based on where the modal will
* snap to upon release.
*/
snapBreakpoint?: number;
}
```

## Accessibility

### Keyboard Interactions
Expand Down
2 changes: 2 additions & 0 deletions docs/api/range.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ import CSSProps from '@site/static/usage/v8/range/theming/css-properties/index.m

Range includes [CSS Shadow Parts](#css-shadow-parts) to allow complete customization of specific element nodes within the Range component. CSS Shadow Parts offer the most customization capabilities and are the recommended approach when requiring advance styling with the Range component.

When `dualKnobs` is enabled, additional Shadow Parts are exposed to allow each knob to be styled independently. These are available in two forms: **static identity parts** (`A` and `B`) and **dynamic position parts** (`lower` and `upper`). The A and B parts always refer to the same physical knobs, even if the knobs cross. In contrast, the lower and upper parts reflect the current value position and automatically swap if the knobs cross. This allows styling by consistent identity or by relative value within the range.

import CSSParts from '@site/static/usage/v8/range/theming/css-shadow-parts/index.md';

<CSSParts />
Expand Down
Loading