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

Modal: Bad position on second show #614

Closed
mishak87 opened this issue Feb 10, 2014 · 64 comments
Closed

Modal: Bad position on second show #614

mishak87 opened this issue Feb 10, 2014 · 64 comments

Comments

@mishak87
Copy link
Contributor

When modal showed for second time it "falls" half bellow screen.

var self = $('.ui.modal');
self.modal({
  onShow: function () {
    self.modal('refresh'); // does NOT help
    setTimeout(function () {
      self.modal('refresh');
    }, 1000); // does help 1s is probably overkill
  }
});

My uneducated guess is position is computed and set only first time when modal is shown and second time default CSS makes it fall.

Modal includes some generated items by KnockoutJS but items are not added between shows.

@jlukic
Copy link
Member

jlukic commented Feb 11, 2014

I can't reproduce any issues from modal docs related to positioning.

Can you make a jsfiddle?

@mishak87
Copy link
Contributor Author

OTR I sent you private demo on your email.

@iamhatesz
Copy link

Same problem as you.
I noticed that after window being closed, margin-top property has still a value. If I set it to 0 via Chrome Inspector it'll show up properly. Even on docs page (http://semantic-ui.com/modules/modal.html) problem occurs. Clicking on "run code" for the second time returns non-centered modal.
Any ideas?

@ab192130
Copy link

Same problem for me

@jlukic
Copy link
Member

jlukic commented Feb 27, 2014

This isnt occurring for me in Chrome/Safari/FF.

Can someone give me their exact browser version and OS who can see this issue?

@iamhatesz
Copy link

OS: Microsoft Windows 7 HP (build 7601, Service Pack 1, latest updates)
Browser: Google Chrome 33.0.1750.117 m (latest for me)

@jlukic
Copy link
Member

jlukic commented Feb 28, 2014

I'm seeing this in chrome as well on windows 7. This is a bug will fix ASAP

@mishak87
Copy link
Contributor Author

❤️

@rottingcorpse
Copy link

Having same issue, ff/chrome/opera @ ubuntu 14.04 b2

@hacknightly
Copy link

It looks like having a set height on the modal fixes this issue for me

@lucidNTR
Copy link

lucidNTR commented Apr 4, 2014

same here problem is solved by setting explicit height of modal...

@FrostBy
Copy link

FrostBy commented Apr 11, 2014

bug is still reproduced

@jlukic
Copy link
Member

jlukic commented Apr 11, 2014

Thanks, could anyone create a JSFiddle that will reproduce the issue?

This might be related to having a parent with a 3D acceleration trigger like backface-visibility or transform

@FrostBy
Copy link

FrostBy commented Apr 11, 2014

@jlukic
I have reproduced the error due to the overridden ".hidden" property
.hidden{
display: none!important;
}
http://jsfiddle.net/d93af/13/

@jlukic jlukic reopened this Apr 11, 2014
@jlukic
Copy link
Member

jlukic commented Apr 11, 2014

I'm using FF 28, Windows 8 and cannot reproduce the error using your JSFiddle.

Am I missing something?

@rottingcorpse
Copy link

My problem was caused by .hidden with !important as well. +1

P.S. Linux ff latest stable, chromium latest stable

@FrostBy
Copy link

FrostBy commented Apr 11, 2014

@jlukic
see the link below
http://goo.gl/ATWsaS

@jlukic
Copy link
Member

jlukic commented Apr 22, 2014

It looks like modals were rebuilding cached sizes on every show instead of just on browser resize. Bad!

I've also fixed modals to work with css that has a rule like .hidden { display: none !important; }

@jlukic jlukic closed this as completed in cd0a5bb Apr 22, 2014
EcomEric pushed a commit to EcomEric/Semantic-UI that referenced this issue Apr 27, 2014
…me common css rules. Fixes issue with cache being cleared on each show
@kwolniak
Copy link

I have the problem with wrong position on 2+ show.
It works OK with semantic 0.15.5. Newest version still have this bug, but when the document or window size is changed, margin of the modal is fixed.

Windows 8
Chrome 34

@jlukic
Copy link
Member

jlukic commented May 12, 2014

@kwolniak Are you having this problem on the docs page or just your site? Can you provide a test-case for this error with latest SUI?

@louis-cl
Copy link

Had same issue, only with "basic" modal though.
Also solved with:
.modal('setting', {}).modal('show')
instead of
.modal({}).modal('show')

@MrOutput
Copy link

MrOutput commented Sep 4, 2015

+1

@David-Tsui
Copy link

How about the image loaded in modal?
I can not make the modal locate in correct location if the image contents in modal are generated before modal showing.

@DavidePastore
Copy link
Contributor

Thanks @speciose and thanks @Kyezil, your solutions work!

@adhatama
Copy link

adhatama commented Oct 9, 2015

The solution from @speciose and @Kyezil works for me. Thanks!

@dubsky
Copy link

dubsky commented Oct 23, 2015

For me this issue happens when I set detachable:true.
When I applied the solution mentioned above, the detachable setting was not applied and therefore the positioning problem disappeared.

I looked into the code and the problem is when detachable=true, on the second show the modal content height is evaluated on a hidden element (too soon) and evaluates to 0, which is wrong.

As a workaround I used the following:

    $('#xxx').modal({ detachable:false, observeChanges:true }).modal('show').modal('refresh');

@Andrew1431
Copy link

None of these fixes are working for me. I have a long form that extends past the page. All works fine, until I have scrolled down and press submit. Upon pressing submit, the modal jumps down and has a huge top margin and is cut off at the bottom of the screen. (Because of a error messages div opening up with a list of all the form invalidation)

trying the .modal('setting', { ... }) is not working for me. Refresh, etc nothing is working :)

@bmalum
Copy link

bmalum commented Feb 22, 2016

doubled (2nd delayed for 100ms) refresh does recenter the Modal - but does not look nice :/

@VasilyShelkov
Copy link

so in my case despite doing

$('.ui.modal')
.modal('attach events', '.button', 'show')
.modal('setting', {
    detachable: false,
    observeChanges: true,
    blurring: true,
    transition: 'vertical flip'
});

Although after doing some CSS comparisons with the examples in the docs, I found that the only difference and what was causing this is some file that just does not exist and isn't mine in http://localhost:8080/scss/_modal.scss which is applying this css to the modal

.modal {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1050;
    display: none;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    outline: 0;
}

Any ideas why this is ?

@aborn
Copy link

aborn commented Mar 18, 2016

@dubsky 's solution can fix the similar problem

@haneefkassam
Copy link

OP's workaround (setting timeout onShow) was the only thing that worked for me (tried all the workarounds posted on this issue).

@fuatsengul
Copy link

My observation:
Problem happens when modal content creating dynamically and changing the content before second show. So modal calculates its vertical centering offset first and it's getting wrong after content has changed.

So my solution is deleting and re-creating whole element rather than replacing its content.

If your environment is similar of mine, it's solid solution.

BTW: add a little delay between creating element and calling it.

@IstoraMandiri
Copy link

@fuatsengul bingo. setting breaks react unfortunately, but your solution worked.

    this.setState({ modal: args });
    setTimeout(() => {
      $modal.modal('show');
    }, 1)

@jiang-ning
Copy link

hey guys, I meet the same problem on "semantic-ui#^2.1.8", I replaced two css defines in my custom css file(because the whole semantic-ui in my .gitignore), and it works fine for me:
@media only screen and (max-width: 767px) { .ui.modal { margin: 0 auto; left: 0; } } @media only screen and (min-width: 768px) { .ui.modal { margin: 0 auto; left: 0; } }
the 'left:0' is for replace 'left:50%' in class '.ui.modal'

@raviroyind
Copy link

This is still a bug, modal opens at different position when opened second time.

@blacksmithblack
Copy link

setTimeout works for me.

Is this problem due to the positioning taking place before the modal has fully loaded?

@mklnz
Copy link

mklnz commented Jul 3, 2016

I'm using Semantic UI with Ember and having the same issue. I've tried all the fixes detailed here and I'm not really having any luck. setTimeout works, but over a slow connection this can be unpredictable.

@blacksmithblack
Copy link

@mklnz ... I ended up loosing the modal ... I tried the following but it caused more problems further down the line. It goes through any div's inside the modal, calculates their individual height and changes the height of the modal.

$(modalID).children().each(function (index, object) { modalHeight += $('#' + object.id).outerHeight(true); }); $(modalID).animate({height: modalHeight},400);

If you are having problems over slow connections use the 'onVisible' call back?

@bartoszkwiedacz
Copy link

bartoszkwiedacz commented Jul 12, 2016

I have the same problem.
First fire of modal:
<div class="ui modal image-comment scrolling transition visible active" style="top: 0px; display: block ! important;">
Second fire:
<div class="ui modal image-comment transition visible active" style="margin-top: -143.5px; display: block ! important;">

Also in second time there is no scrolling class on dimmer element.

@mklnz
Copy link

mklnz commented Jul 19, 2016

After digging around I find the problem with my case is Ember inserts and updates the DOM dynamically, and inserts an image inside the modal div. However, this image has not started loading yet, hence the overall height of the modal container is 0.

Semantic then calculates this as 0 and then shows the modal as margin-top of 0 (calculated). Only after the image actually loads the container has a height, in which case the centering is now incorrect.

I suppose I can find some way to "preload" the image perhaps, before showing the modal?

@raviroyind
Copy link

Entire Semantic-UI framework is fucked up with lots of bugs, the toggle switch does not work after opening & closing modal. I am switching back to bootstrap.

@designosis
Copy link

Thank you @kwolniak and @fuatsengul ... the combination of your discoveries solved my problem.
For me, the only thing that worked was this:

	$('#modal').modal(
		'setting', {
			observeChanges: true,
			// other params here
		}
	);

@chized
Copy link

chized commented Mar 28, 2017

Mine issue was the modal disappears in two seconds, and the content needs to be read. solved it by using the tag instead of the tag I used, though class remain same as ui button.

@amitpatil321
Copy link

.modal{
height: 500px !important;
}

I dont know how but this solution worked for me. I have 3 modal closing and opening after another. and they are in a loop.

@skwny
Copy link

skwny commented Dec 9, 2017

Is there a solid workaround for this yet? I'm getting the same issue. On first open, it's perfectly centered on the screen. On second open, It's positioned at the top of the screen. I've tried recommendations here but no luck :/

@Practice0
Copy link

My solution was to brute force the css ie
$(“#modal”).modal({
onDeny: ...
onApprove: ...
}).modal(“show”);

$(“#modal”).attr(“style”, “top: 10px”);

So I replace the inline styles put in by Semantic UI with my own positioning. In my personal case, it hasn’t broken anything else and seems to be consistently working. I also don’t need it to follow an element but just to show up in full-screen mode in the same position on each open so this works fine for me. Hope this helps!

@skwny
Copy link

skwny commented Dec 10, 2017

Thanks for that. Unfortunately I went ahead and made a reusable modal :/ Not as good as semantic but what can you do?

@magiksd
Copy link

magiksd commented Feb 21, 2018

Hello, I have this issue too, but only in Firefox. For my project, I have fixed it by scrolling the dimmer to 0 :

$('#modal').modal('show');
$('.ui.modals.page.dimmer')[0].scrollTo(0, 0);

@MahmonirB
Copy link

I solved it,
Go to main.js in js folder and change overflow from visible to hidden in this code: $('body').delay(350).css({'overflow': 'hidden'});

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