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

Initial display of swiper contains slides with a width too short to fit dialog width #9

Open
darenyong opened this issue Jun 30, 2020 · 1 comment · May be fixed by #10
Open

Initial display of swiper contains slides with a width too short to fit dialog width #9

darenyong opened this issue Jun 30, 2020 · 1 comment · May be fixed by #10

Comments

@darenyong
Copy link

darenyong commented Jun 30, 2020

Hi, I have attempted to implement the swiper demo into my project (https://coachlogix.github.io/ember-paper-swiper/) and encountered a bug where the width of the slides when the dialog is first opened, do not have a width that matches the width of the dialog.

This bug does not occur in the demo url above.

I'm using ember-cli: 3.11, ember-paper-swiper: 0.0.4

My demo code is a copy-paste of the example:

{{#if showSwiper}}
  {{#paper-swiper as |swiper|}}
   ....
{/if}}

I copied the CSS styles from the demo url above into my project to get the same appearance for the slides.

Please see this basic repo I created which displays the problem here

It looks like the updateContainerWidth() is not triggered correctly when the dialog is first opened. (update: I added a 1sec delay to the debounce and this shows that the dialog loads up showing 1 slide correctly, then when updateContainerWidth() is triggered from didInsertElement, it resizes the dialog width larger to show both slides at the same time. Still investigating what is going on here)

If I resize the browser window after the dialog is opened, then the slides are re-sized corrected and everything looks great.

I noticed the inline style of the slide component is controlled by this code:

widthStyle: computed('containerWidth', function() {
    let containerWidth = this.get('containerWidth');
    return containerWidth ? htmlSafe(`width: ${containerWidth}px`) : null;
}),

Example of problem:

swiper-bug

Any help appreciated, this is a nice component. Thanks.

@darenyong
Copy link
Author

Hi,

Well I found a fix for getting the slides to display correctly (with an inline width style that matches the max-width of md-dialog).

in container.js, I added this:

  didRender() {
    this.updateContainerWidthDebounced();
  },

That seems to ensure the slides always have their width set correctly.

Note that simply increasing the debounce time did not help.

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

Successfully merging a pull request may close this issue.

1 participant