Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fallback placement property for select popover and sameWidth issue fix #873

Merged
merged 3 commits into from
Jun 27, 2023
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
8 changes: 8 additions & 0 deletions packages/crayons-core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1696,6 +1696,10 @@ export namespace Components {
* Error text displayed below the text box.
*/
"errorText": string;
/**
* Alternative placement for popover if the default placement is not possible.
*/
"fallbackPlacements": [PopoverPlacementType];
/**
* If true, the user must select a value. The default value is not displayed.
*/
Expand Down Expand Up @@ -4636,6 +4640,10 @@ declare namespace LocalJSX {
* Error text displayed below the text box.
*/
"errorText"?: string;
/**
* Alternative placement for popover if the default placement is not possible.
*/
"fallbackPlacements"?: [PopoverPlacementType];
/**
* If true, the user must select a value. The default value is not displayed.
*/
Expand Down
65 changes: 40 additions & 25 deletions packages/crayons-core/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Method,
Prop,
h,
Watch,
} from '@stencil/core';
import { createPopper, Instance } from '@popperjs/core';
import { PopoverPlacementType, PopoverTriggerType } from '../../utils/types';
Expand Down Expand Up @@ -184,6 +185,44 @@ export class Popover {
}
}

@Watch('boundary')
@Watch('placement')
@Watch('fallbackPlacements')
handlePlacementChange(): void {
this.popperInstance?.destroy();
this.popperInstance = null;
this.setPopperOptions();
this.updatePopper();
}

setPopperOptions() {
this.popperOptions = {
placement: this.placement,
strategy: this.hoist ? 'fixed' : 'absolute',
modifiers: [
{
name: 'flip',
options: {
fallbackPlacements: this.fallbackPlacements,
},
},
{
name: 'preventOverflow',
options: {
boundary: this.boundary || 'clippingParents',
},
},
{
name: 'offset',
options: {
offset: [Number(this.skidding), Number(this.distance)],
},
},
popperModifierRTL,
],
};
}

componentWillLoad() {
this.contentRef = this.host.querySelector('[slot="popover-content"]');
this.triggerRef = this.host.querySelector('[slot="popover-trigger"]');
Expand Down Expand Up @@ -225,31 +264,7 @@ export class Popover {
}
});
}
this.popperOptions = {
placement: this.placement,
strategy: this.hoist ? 'fixed' : 'absolute',
modifiers: [
{
name: 'flip',
options: {
fallbackPlacements: this.fallbackPlacements,
},
},
{
name: 'preventOverflow',
options: {
boundary: this.boundary || 'clippingParents',
},
},
{
name: 'offset',
options: {
offset: [Number(this.skidding), Number(this.distance)],
},
},
popperModifierRTL,
],
};
this.setPopperOptions();
}

private async delay(ms: number) {
Expand Down
Loading
Loading