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

Application of floating UI helpers within dropdown component #349

Merged
merged 40 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8cca2d3
Add necessary packages
brenner-company Nov 17, 2022
3ff840b
Add floating-ui modifier
brenner-company Nov 17, 2022
885d843
Add floating-ui component
brenner-company Nov 17, 2022
b0b7b56
Add floating-ui story (Storybook)
brenner-company Nov 17, 2022
d431fe7
Add exemplary styling for floating-ui component
brenner-company Nov 17, 2022
8659042
Fix static floater offset & unused variable
brenner-company Nov 17, 2022
ddd25f2
Reorder middleware options
brenner-company Nov 18, 2022
73fb754
Add middleware control & enable default values
brenner-company Nov 18, 2022
9d70b06
Remove middleware argument & restructure middleware settings (bugfix)
brenner-company Nov 21, 2022
d13af70
Fix floating-ui story (missing argument)
brenner-company Nov 21, 2022
1119b6d
Add test coverage for floating-ui modifier & component
brenner-company Nov 21, 2022
ac5f429
Relocate example scroller/floater structure & styling to dummy component
brenner-company Nov 21, 2022
33b7bf6
Disable linting error for a moment (before extending functionality)
brenner-company Nov 22, 2022
1edb52f
Merge branch 'development' into feature/addition-of-floating-ui-helpers
brenner-company Nov 24, 2022
86f7306
Add functionality for the example scroller component
brenner-company Dec 2, 2022
91825a1
Merge branch 'development' into feature/addition-of-floating-ui-helpers
brenner-company Dec 2, 2022
1438f26
Enable use of both negative & positive offset values for the arrow
brenner-company Dec 5, 2022
edec58f
Adjust dropdown component (for floating-ui usage)
brenner-company Dec 7, 2022
a985e0c
Fix faulty tests for the dropdown component
brenner-company Dec 8, 2022
0526e4b
Convert floating-ui modifier to function-based modifier
brenner-company Dec 15, 2022
772fdbe
Merge branch 'feature/addition-of-floating-ui-helpers' into feature/d…
brenner-company Dec 15, 2022
fd16e8b
Switch floating-ui within dropdown from component to modifier
brenner-company Jan 4, 2023
8ef07c7
Remove component version of floating-ui helper
brenner-company Jan 4, 2023
8c7390c
Remove floating-ui Storybook story
brenner-company Jan 4, 2023
827fb07
Delete re-export of floating-ui modifier
brenner-company Jan 4, 2023
062f607
Move floating-ui modifier to private folder & rename identifier
brenner-company Jan 4, 2023
170fbab
Adjust floating-ui modifier assertions
brenner-company Jan 4, 2023
9d5ced4
Move floating-ui modifier test to private folder, rename identifier &…
brenner-company Jan 4, 2023
740b87e
Remove dummy floater styling (not needed anymore)
brenner-company Jan 4, 2023
33d09a6
Merge branch 'feature/addition-of-floating-ui-helpers' into feature/d…
brenner-company Jan 4, 2023
8842d20
Remove example scroller component & styling
brenner-company Jan 5, 2023
38f6213
Merge branch 'feature/addition-of-floating-ui-helpers' into feature/d…
brenner-company Jan 5, 2023
4fe5420
Adjust integration of floating-ui within dropdown component
brenner-company Jan 5, 2023
b6e7adf
Merge branch 'development' into feature/dynamic-display-of-menu-withi…
brenner-company Jan 5, 2023
d7e8d85
Merge branch 'development' into feature/dynamic-display-of-menu-withi…
brenner-company Jan 6, 2023
108ea44
Convert toggle method for dropdown menu from visibility to conditional
brenner-company Jan 6, 2023
e246520
Remove isActive argument on dropdown menu
brenner-company Jan 6, 2023
f037bf3
Update floating-ui package & remove previously added test fix
brenner-company Jan 6, 2023
496006c
Commit changes to lock file regarding floating-ui update
brenner-company Jan 6, 2023
fa130c5
Replace redundant query selector with reference element within dropdo…
brenner-company Jan 6, 2023
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
45 changes: 29 additions & 16 deletions addon/components/au-dropdown.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="au-c-dropdown" ...attributes>
<AuButton
{{this.reference}}
@skin={{this.skin}}
@size={{@size}}
@icon={{this.icon}}
Expand All @@ -17,19 +18,31 @@
{{@title}}
</span>
</AuButton>
<div
class="au-c-dropdown__menu {{this.alignment}} {{if this.dropdownOpen 'is-visible'}}"
role="menu"
tabindex="-1"
{{focus-trap
isActive=this.dropdownOpen
shouldSelfFocus=true
focusTrapOptions=(hash
clickOutsideDeactivates=this.clickOutsideDeactivates
)
}}
{{on "click" this.closeDropdown}}
>
{{yield}}
</div>
</div>
{{#if this.dropdownOpen}}
<div
{{this.floatingUi
this.referenceElement
this.arrowElement
defaultPlacement=this.alignment
options=this.floatingUiOptions
}}
class="au-c-dropdown__floater"
>
<div {{this.arrow}} class="au-c-dropdown__arrow"></div>
<div
{{focus-trap
shouldSelfFocus=true
focusTrapOptions=(hash
clickOutsideDeactivates=this.clickOutsideDeactivates
)
}}
{{on "click" this.closeDropdown}}
class="au-c-dropdown__menu"
role="menu"
tabindex="-1"
>
{{yield}}
</div>
</div>
{{/if}}
</div>
40 changes: 35 additions & 5 deletions addon/components/au-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,30 @@ import Component from '@glimmer/component';
import { deprecate } from '@ember/debug';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { modifier } from 'ember-modifier';

import FloatingUiModifier from '@appuniversum/ember-appuniversum/private/modifiers/floating-ui';

export default class AuDropdown extends Component {
@tracked referenceElement = undefined;
@tracked arrowElement = undefined;

floatingUi = FloatingUiModifier;

reference = modifier(
(element) => {
this.referenceElement = element;
brenner-company marked this conversation as resolved.
Show resolved Hide resolved
},
{ eager: false }
);

arrow = modifier(
(element) => {
this.arrowElement = element;
},
{ eager: false }
);

@tracked dropdownOpen = false;

@action
Expand All @@ -23,8 +45,7 @@ export default class AuDropdown extends Component {

@action
clickOutsideDeactivates(event) {
let toggleButton = document.querySelector('[data-au-dropdown-toggle]');
let isClosedByToggleButton = toggleButton.contains(event.target);
let isClosedByToggleButton = this.referenceElement.contains(event.target);

if (!isClosedByToggleButton) {
this.closeDropdown();
Expand Down Expand Up @@ -52,9 +73,9 @@ export default class AuDropdown extends Component {

// Dropdown alignment
get alignment() {
if (this.args.alignment == 'left') return 'au-c-dropdown__menu--left';
if (this.args.alignment == 'right') return 'au-c-dropdown__menu--right';
return '';
if (this.args.alignment == 'left') return 'bottom-start';
brenner-company marked this conversation as resolved.
Show resolved Hide resolved
if (this.args.alignment == 'right') return 'bottom-end';
return 'bottom';
}

// Set default button skin
Expand All @@ -74,4 +95,13 @@ export default class AuDropdown extends Component {
if (this.args.iconAlignment) return this.args.iconAlignment;
else return 'right';
}

// Set options for the floatingUi component
get floatingUiOptions() {
return {
arrow: {
offset: 0,
},
};
}
}
74 changes: 21 additions & 53 deletions app/styles/ember-appuniversum/_c-dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
$au-dropdown-caret-size : .4rem !default;

/* Component
========================================================================== */
========================================================================== */

.au-c-dropdown {
position: relative;
display: inline-block;
}

Expand All @@ -38,31 +37,28 @@ $au-dropdown-caret-size : .4rem !default;
}
}

.au-c-dropdown__menu {
@include au-font-size(var(--au-base),1.5);
font-family: var(--au-font);
font-weight: var(--au-regular);
position: absolute;
.au-c-dropdown__floater {
z-index: var(--au-z-index-beta);
background-color: var(--au-white);
display: flex;
flex-direction: column;
flex-wrap: nowrap;
left: 50%;
transform: translateX(-50%);
min-width: 100%;
width: auto;
top: calc(100% + #{$au-unit-tiny});

box-shadow: 0 0 12px rgba($au-gray-900,.15), 0 0 2px rgba($au-gray-900,.1);
border-radius: var(--au-radius);
display: none;
background-color: var(--au-white);

@include au-font-size(var(--au-base),1.5);
font-family: var(--au-font);
font-weight: var(--au-regular);
}

.au-c-dropdown__arrow {
position: absolute;

&:before,
&:after {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
content: "";
height: 0;
width: 0;
position: absolute;
Expand All @@ -80,46 +76,18 @@ $au-dropdown-caret-size : .4rem !default;
border-color: rgba($au-white, 0);
border-bottom-color: var(--au-white);
}
}

.au-c-dropdown__menu {
position: relative;
z-index: var(--au-z-index-beta); // Re-apply z-index to fix overlapping arrow when focussing on a menu item
display: flex;
flex-direction: column;
flex-wrap: nowrap;

&:focus {
outline: 0;
}

&.is-visible {
display: flex;
}

// Modify the menu position
&.au-c-dropdown__menu--left,
&.au-c-dropdown__menu--right {
transform: none;
}

&.au-c-dropdown__menu--left {
left: 0;
}

&.au-c-dropdown__menu--right {
left: auto;
right: 0;
}

&.au-c-dropdown__menu--left:after {
left: $au-unit-small;
}

&.au-c-dropdown__menu--right:after {
right: $au-unit-small + $au-unit-tiny;
left: auto;
}

.au-c-button--naked + &.au-c-dropdown__menu--left:after {
left: $au-unit-tiny;
}

.au-c-button--naked + &.au-c-dropdown__menu--right:after {
right: $au-unit-tiny;
}
}

.au-c-dropdown__menu > .au-c-hr {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"dependencies": {
"@duetds/date-picker": "^1.4.0",
"@embroider/macros": "^1.9.0",
"@floating-ui/dom": "^1.0.4",
"@floating-ui/dom": "^1.1.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@zestia/ember-auto-focus": "^4.2.0",
Expand Down