Skip to content

Commit 8905696

Browse files
feat(content): add fixedSlotPlacement prop (#29233)
Issue number: Internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Content in the `fixed` slot is always placed after the main content in the DOM. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - A new `fixedSlotPlacement` prop on Content allows developers to place fixed content either before or after the main content in the DOM ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#footer for more information. --> ## Other information Dev build: `8.0.0-dev.11712072527.1dd97c66` <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> ⚠️This feature will not be part of the v8.0 release. As a result, do not merge this into `feature-8.0`. However, I am putting this PR up based off `feature-8.0` so it can get reviewed by the team. --------- Co-authored-by: Liam DeBeasi <[email protected]>
1 parent 59b72f4 commit 8905696

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ ion-col,css-prop,--ion-grid-columns
361361

362362
ion-content,shadow
363363
ion-content,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
364+
ion-content,prop,fixedSlotPlacement,"after" | "before",'after',false,false
364365
ion-content,prop,forceOverscroll,boolean | undefined,undefined,false,false
365366
ion-content,prop,fullscreen,boolean,false,false,false
366367
ion-content,prop,scrollEvents,boolean,false,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,10 @@ export namespace Components {
762762
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
763763
*/
764764
"color"?: Color;
765+
/**
766+
* Controls where the fixed content is placed relative to the main content in the DOM. This can be used to control the order in which fixed elements receive keyboard focus. For example, if a FAB in the fixed slot should receive keyboard focus before the main page content, set this property to `'before'`.
767+
*/
768+
"fixedSlotPlacement": 'after' | 'before';
765769
/**
766770
* If `true` and the content does not cause an overflow scroll, the scroll interaction will cause a bounce. If the content exceeds the bounds of ionContent, nothing will change. Note, this does not disable the system bounce on iOS. That is an OS level setting.
767771
*/
@@ -5482,6 +5486,10 @@ declare namespace LocalJSX {
54825486
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
54835487
*/
54845488
"color"?: Color;
5489+
/**
5490+
* Controls where the fixed content is placed relative to the main content in the DOM. This can be used to control the order in which fixed elements receive keyboard focus. For example, if a FAB in the fixed slot should receive keyboard focus before the main page content, set this property to `'before'`.
5491+
*/
5492+
"fixedSlotPlacement"?: 'after' | 'before';
54855493
/**
54865494
* If `true` and the content does not cause an overflow scroll, the scroll interaction will cause a bounce. If the content exceeds the bounds of ionContent, nothing will change. Note, this does not disable the system bounce on iOS. That is an OS level setting.
54875495
*/

core/src/components/content/content.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ export class Content implements ComponentInterface {
7575
*/
7676
@Prop() fullscreen = false;
7777

78+
/**
79+
* Controls where the fixed content is placed relative to the main content
80+
* in the DOM. This can be used to control the order in which fixed elements
81+
* receive keyboard focus.
82+
* For example, if a FAB in the fixed slot should receive keyboard focus before
83+
* the main page content, set this property to `'before'`.
84+
*/
85+
@Prop() fixedSlotPlacement: 'after' | 'before' = 'after';
86+
7887
/**
7988
* If `true` and the content does not cause an overflow scroll, the scroll interaction will cause a bounce.
8089
* If the content exceeds the bounds of ionContent, nothing will change.
@@ -423,7 +432,7 @@ export class Content implements ComponentInterface {
423432
}
424433

425434
render() {
426-
const { isMainContent, scrollX, scrollY, el } = this;
435+
const { fixedSlotPlacement, isMainContent, scrollX, scrollY, el } = this;
427436
const rtl = isRTL(el) ? 'rtl' : 'ltr';
428437
const mode = getIonMode(this);
429438
const forceOverscroll = this.shouldForceOverscroll();
@@ -446,6 +455,9 @@ export class Content implements ComponentInterface {
446455
}}
447456
>
448457
<div ref={(el) => (this.backgroundContentEl = el)} id="background-content" part="background"></div>
458+
459+
{fixedSlotPlacement === 'before' ? <slot name="fixed"></slot> : null}
460+
449461
<div
450462
class={{
451463
'inner-scroll': true,
@@ -467,7 +479,7 @@ export class Content implements ComponentInterface {
467479
</div>
468480
) : null}
469481

470-
<slot name="fixed"></slot>
482+
{fixedSlotPlacement === 'after' ? <slot name="fixed"></slot> : null}
471483
</Host>
472484
);
473485
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { newSpecPage } from '@stencil/core/testing';
2+
3+
import { Content } from '../content';
4+
5+
describe('content: fixed slot placement', () => {
6+
it('should should fixed slot after content', async () => {
7+
const page = await newSpecPage({
8+
components: [Content],
9+
html: '<ion-content></ion-content>',
10+
});
11+
12+
const content = page.body.querySelector('ion-content')!;
13+
const fixedSlot = content.shadowRoot!.querySelector('slot[name="fixed"]')!;
14+
const scrollEl = content.shadowRoot!.querySelector('[part="scroll"]')!;
15+
16+
expect(fixedSlot.nextElementSibling).not.toBe(scrollEl);
17+
});
18+
19+
it('should should fixed slot before content', async () => {
20+
const page = await newSpecPage({
21+
components: [Content],
22+
html: `<ion-content fixed-slot-placement="before"></ion-content>`,
23+
});
24+
25+
const content = page.body.querySelector('ion-content')!;
26+
const fixedSlot = content.shadowRoot!.querySelector('slot[name="fixed"]')!;
27+
const scrollEl = content.shadowRoot!.querySelector('[part="scroll"]')!;
28+
29+
expect(fixedSlot.nextElementSibling).toBe(scrollEl);
30+
});
31+
});

packages/angular/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,15 @@ export declare interface IonCol extends Components.IonCol {}
592592

593593

594594
@ProxyCmp({
595-
inputs: ['color', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
595+
inputs: ['color', 'fixedSlotPlacement', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
596596
methods: ['getScrollElement', 'scrollToTop', 'scrollToBottom', 'scrollByPoint', 'scrollToPoint']
597597
})
598598
@Component({
599599
selector: 'ion-content',
600600
changeDetection: ChangeDetectionStrategy.OnPush,
601601
template: '<ng-content></ng-content>',
602602
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
603-
inputs: ['color', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
603+
inputs: ['color', 'fixedSlotPlacement', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
604604
})
605605
export class IonContent {
606606
protected el: HTMLElement;

packages/angular/standalone/src/directives/proxies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,15 @@ export declare interface IonCol extends Components.IonCol {}
659659

660660
@ProxyCmp({
661661
defineCustomElementFn: defineIonContent,
662-
inputs: ['color', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
662+
inputs: ['color', 'fixedSlotPlacement', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
663663
methods: ['getScrollElement', 'scrollToTop', 'scrollToBottom', 'scrollByPoint', 'scrollToPoint']
664664
})
665665
@Component({
666666
selector: 'ion-content',
667667
changeDetection: ChangeDetectionStrategy.OnPush,
668668
template: '<ng-content></ng-content>',
669669
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
670-
inputs: ['color', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
670+
inputs: ['color', 'fixedSlotPlacement', 'forceOverscroll', 'fullscreen', 'scrollEvents', 'scrollX', 'scrollY'],
671671
standalone: true
672672
})
673673
export class IonContent {

packages/vue/src/proxies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export const IonCol = /*@__PURE__*/ defineContainer<JSX.IonCol>('ion-col', defin
262262
export const IonContent = /*@__PURE__*/ defineContainer<JSX.IonContent>('ion-content', defineIonContent, [
263263
'color',
264264
'fullscreen',
265+
'fixedSlotPlacement',
265266
'forceOverscroll',
266267
'scrollX',
267268
'scrollY',

0 commit comments

Comments
 (0)