Skip to content

Commit

Permalink
feat(dropdown): thyPopoverOptions support outsideClosable params (#3144)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggxxgxq authored Aug 14, 2024
1 parent 4cc0ae2 commit 3fa855b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/dropdown/dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export class ThyDropdownDirective extends ThyOverlayDirectiveBase implements OnI
@Input() thyActiveClass: string = 'thy-dropdown-origin-active';

/**
* 弹出框的参数,底层使用 Popover 组件, 默认为`{ placement: "bottomLeft", insideClosable: true, minWidth: "240px" }`
* @default { placement: "bottomLeft", insideClosable: true, minWidth: "240px" }
* 弹出框的参数,底层使用 Popover 组件, 默认为`{ placement: "bottomLeft", insideClosable: true, minWidth: "240px", outsideClosable: true }`
* @default { placement: "bottomLeft", insideClosable: true, minWidth: "240px", outsideClosable: true }
*/
@Input() thyPopoverOptions: Pick<ThyPopoverConfig, 'placement' | 'height' | 'insideClosable' | 'minWidth'>;
@Input() thyPopoverOptions: Pick<ThyPopoverConfig, 'placement' | 'height' | 'insideClosable' | 'minWidth' | 'outsideClosable'>;

/**
* 弹出框的显示位置,会覆盖 thyPopoverOptions 中的 placement,`top` | `topLeft` | `topRight` | `bottom` | `bottomLeft` | `bottomRight` | `left` | `leftTop` | `leftBottom` | `right` | `rightTop` | `rightBottom`
Expand Down Expand Up @@ -155,8 +155,8 @@ export class ThyDropdownDirective extends ThyOverlayDirectiveBase implements OnI
}
}

const { placement, height, insideClosable, minWidth } = Object.assign(
{ placement: 'bottomLeft', insideClosable: true },
const { placement, height, insideClosable, outsideClosable, minWidth } = Object.assign(
{ placement: 'bottomLeft', insideClosable: true, outsideClosable: true },
this.thyPopoverOptions
);
const config: ThyPopoverConfig = {
Expand All @@ -167,7 +167,7 @@ export class ThyDropdownDirective extends ThyOverlayDirectiveBase implements OnI
panelClass: this.thyPanelClass,
placement: this.thyPlacement ? this.thyPlacement : placement,
height,
outsideClosable: true,
outsideClosable,
insideClosable: helpers.isUndefined(this.thyMenuInsideClosable) ? insideClosable : this.thyMenuInsideClosable,
minWidth,
originActiveClass: this.thyActiveClass
Expand Down
5 changes: 4 additions & 1 deletion src/dropdown/examples/options/options.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<form thyForm thyLayout="inline">
<form thyForm>
<thy-form-group thyLabelText="Placement">
<thy-native-select [(ngModel)]="popoverOptions.placement" name="placement">
<option value="top">top</option>
Expand All @@ -21,6 +21,9 @@
<thy-form-group thyLabelText="MinWidth">
<thy-input-number [(ngModel)]="popoverOptions.minWidth" name="min-width"></thy-input-number>
</thy-form-group>
<thy-form-group class="align-items-center" thyLabelText="OutsideClosable">
<thy-switch class="dropdown-switch" [(ngModel)]="popoverOptions.outsideClosable" name="outsideClosable"></thy-switch>
</thy-form-group>
</form>

<button
Expand Down
4 changes: 3 additions & 1 deletion src/dropdown/examples/options/options.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export class ThyDropdownOptionsExampleComponent {
placement?: ThyPlacement;
height?: string | number;
minWidth?: string | number;
outsideClosable?: boolean;
} = {
placement: 'bottom',
height: 108,
minWidth: '200px'
minWidth: '200px',
outsideClosable: true
};

placement: ThyPlacement = 'bottomRight';
Expand Down
13 changes: 13 additions & 0 deletions src/dropdown/test/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ describe('dropdown options', () => {
placement: 'bottomLeft',
height: undefined,
insideClosable: true,
outsideClosable: true,
hasBackdrop: false,
offset: 0,
originActiveClass: 'thy-dropdown-origin-active'
Expand Down Expand Up @@ -1074,6 +1075,18 @@ describe('dropdown options', () => {
);
});

it('should set outsideClosable', () => {
dropdown.thyPopoverOptions.outsideClosable = false;

expect(calledConfig).toBeUndefined();
dropdown.createOverlay();
expect(calledConfig).toEqual(
jasmine.objectContaining({
outsideClosable: false
})
);
});

it('should set panel class', () => {
dropdown.thyPanelClass = 'test-dropdown-panel-class';

Expand Down

0 comments on commit 3fa855b

Please sign in to comment.