components icon indicating copy to clipboard operation
components copied to clipboard

Can't drag md-slider

Open allurefx opened this issue 9 years ago • 47 comments

Bug, feature request, or proposal:

Looks like a bug, but it could be user error (I'm new to Material)

What is the expected behavior?

Should be able to drag on md-slider

What is the current behavior?

Drag doesn't work, though click on slider does set the value

What are the steps to reproduce?

Please check out http://ravinutala.com/d/index.html for an example with just the slider

What is the use-case or motivation for changing an existing behavior?

Just want the correct behavior, not asking for any changes

Which versions of Angular, Material, OS, browsers are affected?

Angular 4.0.3, Material 2.0.0-beta.3, Windows 10, Chrome/FF (only tested on these two)

Is there anything else we should know?

allurefx avatar Apr 26 '17 03:04 allurefx

You need to import MaterialModule after either BrowserAnimationsModule or BrowserModule (probably just best to put it after both).

Unfortunately, I couldn't tell you why

willshowell avatar Apr 26 '17 14:04 willshowell

I'm getting this issue too. I have tried your suggestion @willshowell but it still doesn't work. It also advises that MaterialModule is now deprecated. I've tried importing the MdSliderModule in the same way though, after BrowserModule and BrowserAnimationsModule, to no avail.

I can't help but think this is something to do with hammerjs, but I'm sure I have followed the Getting Started guide properly.

A little stumped... :/

stevedeighton avatar Apr 26 '17 14:04 stevedeighton

@stevedeighton Can you provide a bare-minimum repo?

willshowell avatar Apr 26 '17 14:04 willshowell

Thanks a lot, @willshowell, that was it: I just had to move MaterialModule after BrowserAnimationsModule (and before BrowserModule, FYI). @stevedeighton, did you change the order in the imports array of @NgModule?

allurefx avatar Apr 26 '17 15:04 allurefx

@allurefx yep I did that, I'll have another play later tonight with it and provide a demo if I'm still struggling Thanks @willshowell :D

stevedeighton avatar Apr 26 '17 15:04 stevedeighton

Aha, found it. I was running angular 4.0.0 still. Upgraded to 4.0.3 and its working now 👍

stevedeighton avatar Apr 26 '17 15:04 stevedeighton

My guess is that hammerjs isn't loaded yet when the angular app is bootstrapped.

@jelbourn Is there anything we can do to improve this? (e.g. autodetect when hammerjs loads or provide a way for users to trigger it to recheck).

mmalerba avatar Apr 26 '17 15:04 mmalerba

@mmalerba I pulled up the repro and found that Hammer is loaded here at bootstrap. The problem is that it's using the default gesture config rather than the one from material. Haven't figured out why yet.

jelbourn avatar Apr 26 '17 16:04 jelbourn

@allurefx what does your app module (that you're bootstrapping) look like?

jelbourn avatar Apr 26 '17 16:04 jelbourn

Oh, reading the whole thread now I see. If BrowserModule is added after MaterialModule, its gesture config overrides the one slider needs. Wonder if there's anything we can do about tnat.

jelbourn avatar Apr 26 '17 16:04 jelbourn

@jelbourn, the problem appears to be with importing MaterialModule before BrowserAnimationsModule; BrowserModule location doesn't appear to matter. E.g.,

Below one does NOT work imports: [MaterialModule, BrowserAnimationsModule, BrowserModule, HttpModule]

Below ones both work imports: [BrowserAnimationsModule, MaterialModule, BrowserModule, HttpModule] imports: [BrowserAnimationsModule, BrowserModule, MaterialModule, HttpModule]

allurefx avatar Apr 26 '17 16:04 allurefx

Looked into it a bit, and unfortunately there's no mechanism for our modules to effectively say "My provider is more important than your provider" (and also no way to change BrowserModule so that it can say that it's less important).

Best we can do for now is to document that the order matters; sent #4291 for this

jelbourn avatar Apr 26 '17 18:04 jelbourn

Hi, I just wanted to point out that I found out another weird behavior. In order to make md-slider work together with hammerjs inside a lazy loaded module, I have to import MdSliderModule both in the main App.module and in the Lazy.module. This is a wasteful import since I only use MdSliderModule inside the LazyModule.

iliketomatoes avatar May 12 '17 13:05 iliketomatoes

@iliketomatoes could you please open a separate issue for this with minimal repro

mmalerba avatar May 12 '17 16:05 mmalerba

@iliketomatoes dude you are a life saver! I've spent all day trying to figure out why the md-slider would work with ng serve and not when built with ng build.

yo-epicdavid avatar May 26 '17 12:05 yo-epicdavid

I had this problem because i forgot to import 'hammerjs'; in the app's root module, I also upgraded angular with npm i @angular/common@latest @angular/compiler@latest @angular/core@latest @angular/forms@latest @angular/http@latest @angular/platform-browser@latest @angular/platform-browser-dynamic@latest @angular/platform-server@latest @angular/router@latest typescript@latest --S -E

then npm i @angular/compiler-cli@latest --D -E and it was solved

tdr2d avatar Jun 09 '17 23:06 tdr2d

The import order solution never worked for me, though it does seem to be related to something overriding Hammer gestures. I was able to get it working with the following in app module.

import { BrowserModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { GestureConfig, MaterialModule } from '@angular/material';

// Angular material has a bug with the import order of browserModule and angular material which causes Hammger gestures to get overridden.
@NgModule({
  providers: [
    { provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }
  ]
});

chasemgray avatar Jul 25 '17 18:07 chasemgray

My issue was due to missing hammerjs. Docs note that hammerjs is required for the slider gesters

npm install hammerjs --save

marc-wilson avatar Jul 28 '17 03:07 marc-wilson

I have the same problem. I've configured hammer to allow vertical scroll on pan section:

export class MyHammerConfig extends HammerGestureConfig {

  buildHammer(element: HTMLElement) {

      let mc = new Hammer(element, {

          touchAction: "pan-y",

      });

      return mc;

  }

}

and now slider doesn't drag fine. If i remove this settings everything works fine. Maybe it overwrites something?

ghost avatar Sep 08 '17 09:09 ghost

Same problem here. I never needed to import MaterialModule at all. That threw me off at first reading through this thread. I followed the directions in the accepted answer here and the animation worked. (I missed in the docs where hammerjs must be running on the page).

hodglem avatar Sep 20 '17 15:09 hodglem