Comments (6)
Thanks for the report. Care to post a repro? Thanks!
from shoelace.
Press Esc
- Open sl.rt.ht/1801? that contains an
<sl-dropdown>
within an<sl-drawer>
. - Click on the
<sl-button>
or focus on it and press Enter or Space.- This opens the
<sl-dropdown>
withdocument.activeElement
being the<sl-button>
⚠️ .
- This opens the
- Press Esc, without selecting any
<sl-menu-item>
.- This closes not only the
<sl-dropdown>
, but also the<sl-drawer>
containing it ❌.
- This closes not only the
Observation
If you open <sl-dropdown>
by pressing ↓/↑ instead, document.activeElement
is an <sl-menu-item>
.
<sl-dropdown>
(or perhaps the <sl-menu>
itself) captures the Esc event according to expectations in that case.
Suggestion
<sl-dropdown><sl-button slot=trigger>
can be made to treat Enter and Space the same way as it does ↓.
Important
<sl-dropdown>
can be used with non-<sl-menu>
panel content!
The ↓(/↑) is a special treatment for <sl-menu><sl-menu-item>
s.
Note
Enter/Space and click focuses the first element in other platforms/libraries.
It can be difficult to determine what to focus on when arbitrary panel content elements are involved.
Click outside <sl-dropdown>
inside <sl-drawer>
@IshanJaiswal99 – I cannot reproduce this (with 2.12.0
).
sl.rt.ht/1801? 👈🏻 minimal playground
from shoelace.
@claviska @CetinSert possibly this issue with the react version of shoelace, I am attaching a codesandbox react project demonstrating the issues and I can confirm that I am facing this same issue in my local projects as well so it's not something specific to online IDEs.
Steps to reproduce:
- Click on the Open Drawer Button
- Click on Color Picker / Open Dialog Button / Dropdown Button
- Close the opened Color Picker / Dialog / Dropdown by clicking on the dedicated close buttons or on the overlay of the opened component in order to close it.
Expected:
The opened component should close while the drawer should stay opened
Actual
The opened component is getting closed as well as the drawer in the background is getting closed automatically.
from shoelace.
We have reproduced 2 independent issues:
from shoelace.
As you can see from this example, the issue isn't coming from the library itself.
https://codepen.io/claviska/pen/OJqmXqO?editors=1010
The problem is here:
Indeed, the other components emit sl-hide
and sl-after-hide
just like every HTML element emits a click
event when clicked. The events bubbles, so you need to check the target to make sure you're closing only when the drawer is emitting the event.
I've written about this more here, including a number of ways to do this check.
https://www.abeautifulsite.net/posts/custom-event-names-and-the-bubbling-problem/
from shoelace.
I believe that these types of events bubbling is not an ideal pattern for the library. Not all events need to bubble. Native click
events bubble because a tree branch is being clicked, and it makes sense that if you click content inside of a <button>
element (for example) you will want to know if the button was clicked. Native load
events do not bubble, as load events do not have to do with a whole tree branch: if an <img>
element nexted inside of a <button>
(for sake of example) loads, that does not have to do with the <button>
(the button did not load).
In this sense, the issue is coming from the library, because it when something is working and then it breaks due to changing the composition of the tree, unexpected defensive code (checking event.target
) is required when most likely it should not be needed and better pattern exist (for example we can use the Lit Context API to explicitly create communication channels between higher levels and lower levels of the DOM tree)
from shoelace.
Related Issues (20)
- Events should subclass Event instead of using CustomEvents HOT 3
- Autofocus doesn't work on sl-input in Firefox and Safari HOT 9
- Submenus in dropdown panels don't scroll HOT 1
- <sl-color-picker hoist> causes warning due to non-passive touchmove listener HOT 2
- sl-drawer issues when using keyboard navigation HOT 1
- Event bubbling doesn't appear to be working as described: event bubbles up then circles back around to the child element HOT 1
- events like sl-hide bubbling is confusing HOT 1
- page shake when dialog opend HOT 3
- sl-popup in scrollable section in<dialog> gets clipped in safari
- Dark theme not working, when installed via NPM HOT 1
- Form can still be implicitly submitted when primary button is a disabled shoelace component HOT 1
- sl-select: the small element used as an optgroup title should have its display set to block HOT 1
- Combining dropdown, menu and triggering a drawer causes a weird show animation HOT 4
- Component type resolution fails including Vue types HOT 4
- Translation mistake
- sl-range tooltip causes expensive layout recalc even when not visible
- `sl-divider` doesn't render in SvelteKit app using Autoloader
- Button Group: Artifact in render in dropdown control
- Select: incorrect size rendering in render in dropdown control
- Form Controls: Error Messages: Firefox: Error Message Sticky on Page
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shoelace.