-
-
Notifications
You must be signed in to change notification settings - Fork 193
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
Add watchDrag
option
#416
Comments
I've had a look on how to achieve such a thing and I think the most versatile way of doing this would be to add a new options in order to allow a touch target check function, something like this: TS
Example
ATM it only impact the I would be happy to submit a PR if this feature present an interest to you and the community. Best regards, |
Hi @peacepostman, Thank you for your bug report or feature request? I can't decide what to call it 🙂. However, I think the following needs to be considered at this stage: Adding a scrollable element inside a slide can cause problems, for example, if devs make it too big. In these cases, there won't be anywhere to grab the carousel itself because the scrollable element will swallow touch events. How would one solve that? Checking if the scrollable element has reached its end? This will significantly increase complexity. I'm open to other suggestions if you have something else in mind. Best, |
Hello @davidjerleke , Thanks for your answer, I agree that it is more a feature request than a bug but it started has a surprise and lead to a potential need ^^ I don't know if this is some something doable but another possibility would be to extend the By doing so, the user will still be free to continu to provide a boolean value or make a possible complex checking in order to disable dragging and drag/scroll a nested child. In my point of view the library doesn't have to check all the potential complexity you mentioned previously, but if this is something needed, exposing a way of doing it can be interesting. Best regards, |
would like to see this feature asap. It's just what embla is missing right now |
Just thought of the temporary solution which is not perfect ofc. The issue in that solution is that a 3d translation (scroll effect) disappears if you touch the element while carousel is scrolled + you can't scroll carousel down/up if you touch element & reached its end of the scroll area. Example: https://domin.pro/ (white section cards) // Query select all the scrollable elements we want to apply our draggable state to
document.querySelectorAll('An element to scroll')?.forEach((element: Element) => {
// When you hold that element the carousel isn't scrollable
element.addEventListener('touchstart', () => modScroll(false));
element.addEventListener('touchend', () => modScroll(true));
// Also you could add the same exact event for mouse
});
/**
* Enable or disable dragging on the carousel based on the state
* @param {boolean} state Whether to enable or disable dragging
* @returns {void}
*/
function modScroll(state: boolean): void {
emblaApi?.reInit({
draggable: state,
});
} |
Hello @davidjerleke , thanks for your answer, i'm not able to see it here anymore but nevertheless the provided way to do this is not applicable in my case. Anyway, big thanks for the time you study upon it. If one day you have time to implement something similar to the proposal discussed above, maybe i will be able to solve my issue. In the meantime I was forced to portal out the content inside my slide in order to be able to scroll it. Have a nice day, |
Hi @peacepostman, Sorry for the confusion. I created a sandbox but I realized that it wasn't finished and working as expected. That's why I deleted my comment. I'm the sole dev on this project and with the huge backlog I have, the response time on issues isn't optimal right now. I can't tell when I have time to investigate this further. Thanks for understanding! Best, |
To be released with v8.0.0-rc01. |
Specification
|
@peacepostman and @domin-mnd this feature has been released with v8.0.0-rc01. |
thanks a lot @davidjerleke |
@davidjerleke - This is pretty awesome! I was hoping this option could solve my problem, but looks like it doesn't. I'm trying to disable dragging when clicking or holding next/previous buttons that fire const [emblaRef, emblaApi] = useEmblaCarousel(
{
watchDrag: () => {
return isDragEnabledRef.current;
},
}, Then I set that ref (in React btw) to false on the button's Is there a way to define a scrollable area? Or maybe disable scrolling if the mouse event was initiated inside a certain element? |
Hi @hanshank,
I think you might be misunderstanding the use cases of
The second argument to Best, |
Thanks @davidjerleke, this is exactly what I’ve been looking for! A little more digging around the docs and I would have found it. Thanks for pointing me in the right direction. Really appreciate it. |
Bug is related to
Embla Carousel version
Describe the bug
When a slide has a scrollable content, I am unable to scroll via touch handles. It would be great to have a way to allow this on custom elements/targets.
Bonus question ^^ my slides content are inside a shadow DOM, if there is a possibility to counter my first question, would it be applicable on this context.
CodeSandbox
https://codesandbox.io/s/embla-carousel-y-axis-react-forked-0032js?file=/src/js/EmblaCarousel.tsx
Steps to reproduce
Expected behavior
Best regards,
The text was updated successfully, but these errors were encountered: