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

Carousel Not work IE11 #799

Closed
riazi opened this issue Jan 31, 2018 · 7 comments
Closed

Carousel Not work IE11 #799

riazi opened this issue Jan 31, 2018 · 7 comments

Comments

@riazi
Copy link

riazi commented Jan 31, 2018

Issue description

  • components: Carousel
  • reactstrap version 5.0.0-alpha.4
  • import method umd/csj/es (if umd, are you using the "full" version (only for v5+)?)
  • react version 16.2.0
  • bootstrap version 4.0.0-alpha.6

What is happening?

Carousel Not work IE11when click in carousel-indicators page failed

What should be happening?

Steps to reproduce issue

  1. ...
  2. ...

Error message in console

paste error message with stacktrack here

Code

class Sliderr extends Component {
    constructor(props) {
        super(props);
        this.state = { activeIndex: 0 };
        this.next = this.next.bind(this);
        this.previous = this.previous.bind(this);
        this.goToIndex = this.goToIndex.bind(this);
        this.onExiting = this.onExiting.bind(this);
        this.onExited = this.onExited.bind(this);
    }

    onExiting() {
        this.animating = true;
    }

    onExited() {
        this.animating = false;
    }

    next() {
        if (this.animating) return;
        const nextIndex = this.state.activeIndex === items.length - 1 ? 0 : this.state.activeIndex + 1;
        this.setState({ activeIndex: nextIndex });
    }

    previous() {
        if (this.animating) return;
        const nextIndex = this.state.activeIndex === 0 ? items.length - 1 : this.state.activeIndex - 1;
        this.setState({ activeIndex: nextIndex });
    }

    goToIndex(newIndex) {
        if (this.animating) return;
        this.setState({ activeIndex: newIndex });
    }

    render() {
        const { activeIndex } = this.state;

        const slides = items.map((item) => {
            return (
                <CarouselItem
                    onExiting={this.onExiting}
                    onExited={this.onExited}
                    key={item.src}
                >
                    <img src={item.src} alt={item.altText} />

                    <CarouselCaption captionText={item.description} captionHeader={item.caption} />
                </CarouselItem>
            );
        });

        return (
            <Carousel
                activeIndex={activeIndex}
                next={this.next}
                previous={this.previous}
            >
                <CarouselIndicators items={items} activeIndex={activeIndex} onClickHandler={this.goToIndex} />
                {slides}
                <CarouselControl direction="prev" directionText="Previous" onClickHandler={this.previous} />
                <CarouselControl direction="next" directionText="Next" onClickHandler={this.next} />
            </Carousel>
        );
    }
}


export default Sliderr;
@supergibbs
Copy link
Collaborator

Please see if this is still an issue with the latest release of reactstrap and BS4. If so, can you make an example on stackblitz? You can use https://stackblitz.com/edit/reactstrap-v5-beta-starter as a base

@obinnangini
Copy link

https://stackblitz.com/edit/reactstrap-v5-beta-starter-xdnyqn?file=Example.js

The carousel example available on the reactstrap site does not work in IE once the slide attempts to transition.

@supergibbs
Copy link
Collaborator

The failing code is:

node.dispatchEvent(new CustomEvent('slide.bs.carousel'));

Through sindresorhus/devtools-detect#9 and https://stackoverflow.com/questions/19345392/why-arent-my-parameters-getting-passed-through-to-a-dispatched-event/19345563 it seems we need a polyfill for IE9+
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill

(function () {
  function CustomEvent ( event, params ) {
    params = params || { bubbles: false, cancelable: false, detail: undefined };
    var evt = document.createEvent( 'CustomEvent' );
    evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
    return evt;
   }

  CustomEvent.prototype = window.Event.prototype;

  window.CustomEvent = CustomEvent;
})();

@TheSharpieOne
Copy link
Member

I think this is the only component which actually mimics the bootstrap events. I am not sure if we want the other components to do this or if we want to remove this and just use callbacks as other components currently do.

@supergibbs
Copy link
Collaborator

I am pro not needing polyfills. In the meantime, I confirmed the above one works for this issue on IE11.

jared-dykstra added a commit to jared-dykstra/180-decibels-website that referenced this issue Jan 22, 2019
nathanbacon added a commit to nathanbacon/reactstrap that referenced this issue Jul 19, 2019
This applies the CustomEvent polyfill recommended in the MDN web docs (https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill).
This also applies a simple polyfill for Object.values I found in the react-transition-group module (https://github.com/reactjs/react-transition-group/blob/9e3b2d3c09b78e755bdc837b7b38337812ede2c9/src/TransitionGroup.js#L11).

Fixes reactstrap#799
@jiehan1029
Copy link

I'm having carousel issue with IE 11 again, reactstrap 8.1.1, the problem code is:

../node_modules/reactstrap/es/CarouselItem.js in _this3 at line 62:1
  _proto.onExiting = function onExiting(node) {
    this.setState({
      startAnimation: true
    });
    node.dispatchEvent(new CustomEvent('slide.bs.carousel'));
    this.props.onExiting(node);
  };
  _proto.onExited = function onExited(node) {
    node.dispatchEvent(new CustomEvent('slid.bs.carousel'));

Is it a bug? any workaround?

@jiehan1029
Copy link

nvm, I polyfilled as mentioned above and works fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants