Skip to content

Commit

Permalink
Merge pull request #630 from takenet/bugfix/position-dropdown
Browse files Browse the repository at this point in the history
fix(dropdown): adding property to position the dropdown manually
  • Loading branch information
lucasMurtaVI authored Jul 17, 2023
2 parents 74fa8d6 + 76aeca1 commit 4ed09f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { typeDate } from "./components/datepicker/datepicker";
import { languages } from "./utils/languages";
import { DaysList } from "./components/datepicker/datepicker-interface";
import { stateSelect } from "./components/datepicker/datepicker-period/datepicker-period";
import { activeMode } from "./components/dropdown/dropdown";
import { activeMode, DropdownPostionType } from "./components/dropdown/dropdown";
import { alignItems, breakpoint, direction, flexWrap, gap, justifyContent, margin, padding } from "./components/grid/grid-interface";
import { IconSize, IconTheme, IconType as IconType1 } from "./components/icon/icon-interface";
import { IllustrationType } from "./components/illustration/illustration-interface";
Expand Down Expand Up @@ -580,6 +580,10 @@ export namespace Components {
* Open. Used to open/close the dropdown.
*/
"open"?: boolean;
/**
* Used to set tooltip position
*/
"position"?: DropdownPostionType;
"toggle": () => Promise<void>;
}
interface BdsExpansionPanel {
Expand Down Expand Up @@ -3273,6 +3277,10 @@ declare namespace LocalJSX {
* Open. Used to open/close the dropdown.
*/
"open"?: boolean;
/**
* Used to set tooltip position
*/
"position"?: DropdownPostionType;
}
interface BdsExpansionPanel {
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/dropdown/dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
left: 0;
}

&__center {
left: calc(50% - 122px);
}

&__right {
right: 0;
}
Expand Down
36 changes: 33 additions & 3 deletions src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@ import {
import { getScrollParent, positionAbsoluteElement } from '../../utils/position-element';

export type activeMode = 'hover' | 'click';
export type dropdownPosition = 'bottom' | 'right';
export type dropVerticalPosition = 'bottom' | 'top';
export type dropHorizontalPosition = 'left' | 'center' | 'right';
export type subMenuState = 'close' | 'pending' | 'open';

export type DropdownPostionType =
| 'auto'
| 'top-center'
| 'top-left'
| 'top-right'
| 'bottom-center'
| 'bottom-right'
| 'bottom-left';

@Component({
tag: 'bds-dropdown',
styleUrl: 'dropdown.scss',
Expand Down Expand Up @@ -46,6 +56,11 @@ export class BdsDropdown implements ComponentInterface {
*/
@Prop({ mutable: true, reflect: true }) public open?: boolean = false;

/**
* Used to set tooltip position
*/
@Prop() position?: DropdownPostionType = 'auto';

/**
* bdsToggle. Event to return selected date value.
*/
Expand All @@ -65,7 +80,17 @@ export class BdsDropdown implements ComponentInterface {
}

componentDidLoad() {
this.validatePositionDrop();
if (this.position != 'auto') {
this.setDefaultPlacement(this.position);
} else {
this.validatePositionDrop();
}
}

private setDefaultPlacement(value: DropdownPostionType) {
const arrayPosition = value.split('-');
this.dropElement.classList.add(`dropdown__basic__${arrayPosition[0]}`);
this.dropElement.classList.add(`dropdown__basic__${arrayPosition[1]}`);
}

private validatePositionDrop() {
Expand All @@ -85,7 +110,12 @@ export class BdsDropdown implements ComponentInterface {

@Watch('open')
protected isOpenChanged(open: boolean): void {
if (open) this.validatePositionDrop();
if (open)
if (this.position != 'auto') {
this.setDefaultPlacement(this.position);
} else {
this.validatePositionDrop();
}
}

@Method()
Expand Down
9 changes: 5 additions & 4 deletions src/components/dropdown/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------ | ------------- | -------------------------------------- | -------------------- | --------- |
| `activeMode` | `active-mode` | Open. Used to open/close the dropdown. | `"click" \| "hover"` | `'click'` |
| `open` | `open` | Open. Used to open/close the dropdown. | `boolean` | `false` |
| Property | Attribute | Description | Type | Default |
| ------------ | ------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------- | --------- |
| `activeMode` | `active-mode` | Open. Used to open/close the dropdown. | `"click" \| "hover"` | `'click'` |
| `open` | `open` | Open. Used to open/close the dropdown. | `boolean` | `false` |
| `position` | `position` | Used to set tooltip position | `"auto" \| "bottom-center" \| "bottom-left" \| "bottom-right" \| "top-center" \| "top-left" \| "top-right"` | `'auto'` |


## Events
Expand Down

0 comments on commit 4ed09f8

Please sign in to comment.