Skip to content

Commit

Permalink
* dropdown: set relativeTarget to dropdown menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Oct 11, 2023
1 parent e1fcb3d commit 866658a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/dropdown/src/component/dropdown-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export class DropdownButton extends Button<DropdownButtonOptions> {
}

_updateData() {
const {dropdown, menu, items, onClickItem} = this.props;
const {dropdown, menu, items, onClickItem, relativeTarget = this.triggerElement} = this.props;
const $trigger = $(this.triggerElement);
const instance = Dropdown.get(this.triggerElement);
const options = {
items,
onClickItem,
menu,
relativeTarget,
...dropdown,
};
if (instance) {
Expand Down
5 changes: 3 additions & 2 deletions lib/dropdown/src/types/dropdown-button-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface DropdownButtonOptions extends ButtonProps {
dropdown?: DropdownOptions;
trigger?: DropdownOptions['trigger'];
placement?: DropdownOptions['placement'];
items?: DropdownOptions['items'],
onClickItem?: DropdownOptions['onClickItem'],
items?: DropdownOptions['items'];
relativeTarget?: DropdownOptions['relativeTarget'];
onClickItem?: DropdownOptions['onClickItem'];
}
1 change: 1 addition & 0 deletions lib/dropdown/src/types/dropdown-menu-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import type {SearchMenuOptions} from '@zui/menu/src/types';

export interface DropdownMenuOptions extends SearchMenuOptions {
placement?: Placement;
relativeTarget?: unknown;
}
1 change: 1 addition & 0 deletions lib/dropdown/src/types/dropdown-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import type {DropdownMenuOptions} from './dropdown-menu-options';
export type DropdownOptions = PopoverOptions & {
menu?: Partial<DropdownMenuOptions>,
items?: DropdownMenuOptions['items'],
relativeTarget?: DropdownMenuOptions['relativeTarget'],
onClickItem?: DropdownMenuOptions['onClickItem'],
};
3 changes: 2 additions & 1 deletion lib/dropdown/src/vanilla/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export class Dropdown<O extends DropdownOptions = DropdownOptions> extends Popov
};

protected _getMenuOptions(): DropdownMenuOptions {
const {items, placement, menu, onClickItem} = this.options;
const {items, placement, menu, onClickItem, relativeTarget = this._triggerElement} = this.options;
return {
items,
placement: placement,
onClickItem: onClickItem,
relativeTarget,
...menu,
};
}
Expand Down

0 comments on commit 866658a

Please sign in to comment.