Skip to content

Commit

Permalink
fix(ld-select): using touchend for click outside detection on mobile …
Browse files Browse the repository at this point in the history
…safari
  • Loading branch information
borisdiakur committed Jul 2, 2021
1 parent a6e566e commit 337e63c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
52 changes: 39 additions & 13 deletions src/liquid/components/ld-select/ld-select.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:root {
--ld-select-popper-max-height: 16rem;
--ld-select-popper-max-height: calc(100vh - 1.25rem);
}

.ld-select {
Expand Down Expand Up @@ -86,13 +86,6 @@
}
}

.ld-select--expanded {
z-index: 2147483647; /* Highest possible z-index */
}
.ld-select__popper--expanded {
z-index: 2147483646; /* Highest possible z-index - 1 */
}

.ld-select__popper {
visibility: hidden;
position: absolute;
Expand All @@ -103,8 +96,13 @@
overflow-y: auto;
}

.ld-select--expanded {
z-index: 2147483647; /* Highest possible z-index */
}

.ld-select__popper--expanded {
visibility: inherit;
z-index: 2147483646; /* Highest possible z-index - 1 */

&:after {
content: '';
Expand All @@ -118,9 +116,31 @@
z-index: -1;
}

&.tether-pinned {
z-index: 2147483647;

&:after {
height: 100%;
}

.ld-select__scroll-container {
border-radius: var(--ld-br-m);
}

.ld-option {
&:first-of-type {
border-top-left-radius: var(--ld-br-m);
border-top-right-radius: var(--ld-br-m);
}
&:last-of-type {
border-bottom-left-radius: var(--ld-br-m);
border-bottom-right-radius: var(--ld-br-m);
}
}
}

&.tether-target-attached-bottom,
&.tether-pinned-top,
&[data-popper-placement*='bottom'] {
&.tether-pinned-top {
&:after {
bottom: 0;
}
Expand All @@ -133,16 +153,22 @@
}

&.tether-target-attached-top,
&.tether-pinned-bottom,
&[data-popper-placement*='top'] {
&.tether-pinned-bottom {
&:after {
top: 0;
}

.ld-select__scroll-container {
border-bottom: solid var(--ld-col-rblck1) 1px;
border-top-left-radius: var(--ld-br-m);
border-top-right-radius: var(--ld-br-m);
}
}

&:not(.tether-pinned) {
&.tether-target-attached-top {
.ld-option:last-of-type {
border-bottom: solid var(--ld-col-rblck1) 1px;
}
}
}
}
14 changes: 13 additions & 1 deletion src/liquid/components/ld-select/ld-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class LdSelect {
constraints: [
{
to: 'window',
attachment: 'together none',
// attachment: 'together none', // Enables flipping on scroll.
pin: true,
},
],
Expand Down Expand Up @@ -116,8 +116,10 @@ export class LdSelect {
this.expanded = !this.expanded

if (this.expanded) {
this.popper.enable()
this.updatePopper()
} else {
this.popper.disable()
this.triggerRef.focus()
}
}
Expand Down Expand Up @@ -370,6 +372,16 @@ export class LdSelect {
}
}

// Mobile Safari in some cases does not react to click events on elements
// which are not interactive. But it does to touch events.
@Listen('touchend', {
target: 'window',
passive: true,
})
handleTouchOutside(ev) {
this.handleClickOutside(ev)
}

private handleTriggerClick(ev?: Event) {
if (!this.popper) this.initPopper()

Expand Down

0 comments on commit 337e63c

Please sign in to comment.