-
Notifications
You must be signed in to change notification settings - Fork 6.7k
custom css class in $modal template #892
Comments
+1 |
1 similar comment
+1 |
I believe the idea behind removing |
Yes, that would work pretty well if you defined modal's width in one of the inner elements.. but you don't. And as long as this is supposed to be native javascript plusing for twitter's bootstrap, that |
@fxck I agree - this is exactly the case. |
@fxck and @blnight I'm not understanding why defining the modals width on an inner element would matter in this case. When I say
This way we can define separate templates for separate |
Yes, that's true, but back to what I initally said, you don't usually change anything but the class in the root element. So you'd end up doing this in every initialization. modalTemplate: '<div class="modal fade one-third" ng-class="{in: animate}" ng-transclude></div>' modalTemplate: '<div class="modal fade one-half" ng-class="{in: animate}" ng-transclude></div>' modalTemplate: '<div class="modal fade two-thirds" ng-class="{in: animate}" ng-transclude></div>' modalTemplate: '<div class="modal fade big-ass" ng-class="{in: animate}" ng-transclude></div>' So tell me which is the lesser evil? |
@fxck Well, I definately wouldn't do things that way, I think Regardless, this is just my personal opinion. We'll have to wait on Pawel to decide what the right direction is. |
+1 for a way to vary the width of the modal window. |
Here is a patch to add an extra css class to the window div by specifying it as windowClass option when calling open. Tested with regular jQuery and jQueryLite that comes bundled with angular.
|
After applying the above patch and:
You will find the second modal has the windowClass of the first modal applied. Oh oh! One more change is the solution:
This appears to be a bug in the original implementation. A side effect of merging the defaults and specified options is to replace the memorised options with the merged options. FYI @pkozlowski-opensource |
@fxck @hall5714 so, I'm not sure what is the best way of progressing here. On one hand I hate putting css class names in JS code and I agree here with @hall5714 . At the same time this seems to be the easiest option for developers using the library and I'm buying @fxck argumentation here. So I would say - let's add this option till we can think of a better solution. @richardcrichardc would you be up to sending a pull request, with docs and test update? If not I'm going to look into this item tomorrow, would definitively like to tackle this one before a next release. |
What repo should I fork? It might be quicker if you just copy and paste the changes. I wont be offended if you rename the option or anything. I'm not worried about licences - consider it public domain. Docs: WindowClass: Add an addition css to the DIV containing the modal. Use this to override the css in the template on a modal by modal basis, e.g. to change the width of the modal. On 31/08/2013, at 5:04 AM, Pawel Kozlowski notifications@github.com wrote:
|
Sounds good @pkozlowski-opensource. The one brick wall we are going to run into is Bootstrap 3's new modal layout. For example, the So now, do we put |
Sounds like you might need two different class entry points? |
@jmwolfe Or three if someone has a use-case that requires the borders to be modified. Which is why I suggested the I really wish I could think of a way to do this that doesn't either require template repetition or class ambiguity, but I haven't yet. |
OK, I've been studying the latest module code for a few hours to get the backdrops to stack and block correctly (my Issue #922). Got it working by adding some directive code to set the zIndex. This leads me to an idea for this issue. I don't know if this is "bending" the principles too far, but by setting one or even three classes as options to $modal, wouldn't we really be just passing through options to the modalWindow and modalBackdrop directives, which ARE the places to be messing with the DOM and styles, right? What "far worse" is created by having three class definitions @hall5714? I see many JQuery and Angular Bootstrap modules that have class definitions as part of the passed in options. is it a documentation/comprehension issue? If there is some class interaction issues, we could direct programmers by using names to focus what styles they change, e.g. borderClass, modalSizeClass, etc. |
@jmwolfe There are a number of issues here. For starters, we are passing a CSS class name from a controller, to a service, which compiles a directive, which compiles a template, which has the defined class. It's messy. We are doing things via a service that should be done in a view. And what happens if there is a slight derivation in Bootstrap 3.1 and the modals size is handled in the In addition a future goal of this project is to support additional frameworks. So using the current Foundation reveal (equivalent of Bootstraps model) and your class names would give us this template:
Three separate classes to modify properties on the same element. Kinda icky. Bottom line is this is a tricky situation. Class definitions do not belong in service options, even if they are being passed into a directive. On the flip side, creating a separate template for each class change requires repetitive coding. I just happen to consider the latter the lessor of two evils. But not everyone will agree with me. |
You always need only one class, on the root element. In bootstrap 3 root element happens to be the background layers as well, but who cares. So it still can be on the .modal .modal-dialog {
width: yourwidth;
} and in BT2 .modal {
width: yourwidth;
} |
@fxck True. In fact my first thought was that a simple directive could solve all of this problems: Which would then transclude the modal template in the span:
So you can do hierarchical selectors to get what you need to get done. That said, as of now |
@hall5714 Thanks for taking the time to expand on your concerns. I'm tending towards the repeating templates given all that we need to support. Looking forward to hearing how this plays out. Seems maybe just providing adequate documentation on how to provide effective templates to support your current framework level could eliminate some problems. All I know for sure is, I have to have different size dialogs in my app somehow, and soon. :) |
@fxck @hall5714 @jmwolfe thnx for the great discussion here. I gave is some more thought and here is my proposal: let's add a new option, something like This would allow us to keep CSS out of JS and - at the same time - give people total control over their markup. On top of this one wouldn't be obliged to repeat urls of window templates. In short, the idea is to add an option that would drive a window template to be used. WDYT? |
I'd still rather have css class in js than this. You are gonna get people confused. There will be issues asking why their own template doesn't work, because they forgot to add ng-transclude, they will be asking why it's not animating because they didn't include that ng-class expression. That's my two cents. But as @jmwolfe said, "All I know for sure is, I have to have different size dialogs in my app somehow, and soon.". So it will do I guess. |
@pkozlowski-opensource I like it. Not only does it allow for a custom template (and thus a custom class) but it allows for complete customization of the window without having to define a specific template each time. @fxck I can see what you are saying with people getting confused, but any implementation we use will cause confusion. And a missing |
@fxck I hear what you are saying... and I guess you are right... at the same time I can also envision people coming and asking for other options to be able to change different parts of the window. So I guess supporting people is inevitable anyway :-) I'm going to try to implement the solution with the window type described here, release it asap (by this I mean in 2-3 days) and see what is the feedback from the community. We can always change things as this is still not 1.0 release. |
Sounds like a good plan to me. On 2/09/2013, at 12:43 AM, Pawel Kozlowski notifications@github.com wrote:
|
Well, best so far!. :) If we are going to give them access to the template, though, why not just expose template and/or templateUrl in the options and let them override the default path. If they don't provide any, it will use the window.html template. What I don't like about it is that it is making the user aware of the internals and also mixing up custom files with the delivered templates. Eh. Not a biggie I guess. I'm just not seeing the point of restricting the location of the supplied template (since they are editing it anyway). Seems to be making more work for them than needed. Now they have to be sure of the format of their filename, etc. etc. |
@pkozlowski-opensource the thing is, you can change different parts of the window with that single class. I mean I honestly can't think of any case where I'd need to change anything in the root element. It's pretty much defined by bootstrap what needs a must be there, everything else could should be done from inside. @jmwolfe's got another point.. I can imaging quite a few possible issues with this solution and only about one with the |
Here is an idea, how about two extra options: Different people have different requirements. People who want a bit of extra customisation can use windowClass, people who need more have to specify the whole template. People who want to provide the windowTemplate HTML inline can do so by calling $templateCache.put(). WindowClass was 1 1/2 extra lines of code, windowTemplateUrl is probably not much more. On 2/09/2013, at 6:51 PM, Aleš notifications@github.com wrote:
|
That sounds reasonable. Wouldn't call it "windowClass" though, to me, that sounds like some class you are setting to the body or html tag. I like modalClass or customClass better. |
👍 |
@richardcrichardc @fxck @jmwolfe The reason that having both a windowClass and a windowTemplateUrl is because we are adding two new options that do similar things. We don't need to worry about different paths for the window template using @pkozlowski-opensource's method because And if you guys are worried about 4 or 5 different templates for a simple width change, you can make a very simple directive that has the class name as a configurable option:
And your template for
Now you have the default modal service and a custom modal directive that handles your class name use case without having a bunch of code. More importantly, it's up to you to define custom styles however you like them, rather than defining them in the API of the service. |
@hall5714. The two options do similar things, but they are for different purposes:
You should put that example into the documentation, but hang on, your example HTML is different from the default template:
The original template has ng-transclude but the example does not? What does ng-transclude do anyway? Is it really safe to leave it out? (Rhetorical questions - no need to reply) Allowing users to avoid complexity for common use cases is good. It's no help for me, I ended up forking the codebase so I could have different width windows. Maybe we can save some brain-cycles of people who are yet to discover UI Bootstrap. |
@richardcrichardc I see what you're saying. The problem is I understand that new people coming to Angular may be confused by the template language. That said, we are targeting developers. And with good documentation and examples, the majority are going to be fine. Those that aren't, can open an issue here and will get their answer relatively quickly. Regardless we are getting fairly rhetorical with what users may or may not run into at some point in the future. Let's let @pkozlowski-opensource run with his plan and we'll revisit this if it becomes an issue. |
@hall5714 I apologise for my flippantness. Rhetorical is perhaps not what I should have said. These are genuine questions that went through my mind when looking at your example. But I'm not asking you to answer them. I am trying to illustrate that your solution to customising the width of the dialog is not as simple as you make out. Let's agree we want a simple interface, though disagree on the details. |
@richardcrichardc My fault. My example was really lazy to get a quick example out of the way. In reality it would indeed need to be But there's no such thing as the right implementation, just 10 or 12 opinions on which is right 😄 |
So, what's the current best practice way for defining a new width/height on a modal? All of this conversation is great, but this is inflexible at this point and is just a step back from where we were. EDIT: used @richardcrichardc patch and it's working great. Thanks for putting that together. |
@dmackerman It's a WIP right now and it appears it will be done before the next release (soon). Please keep in mind you are working with the master branch of a repository, not an actual release of the product so expect things to workish, the polish will be there prior to release. |
While we are at it, different situations might require different overlay opacity, if there was a class option, it could apply the class to the overlay as well, that would fix it. If we were to stick with template option.. well, that would a little bigger pain in the arse. |
Aren't the two choices about two separate scenarios? I'd say we should have both, but for now, being able to tweak things via a class would solve my problems. |
@fxck By the overlay I assume you mean the backdrop. I don't think the patch I provided for the class will help with that, as there is a separate template for the backdrop. The 'tweak' class could instead be applied to the backdrop, then a selector like You can see what I mean by examining the code:
Oh oh. Two 'tweak' options ;-). @FYCK Is different overlay opacity between modals a likely requirement. I don't think I would ever want to do that. I would want to tweak the overlay opacity globally, but that doesn't need an extra class. The only use case I can think of is to distinguish dialogs, .e.g. bright red danger overlay for dialogs the user really should pay attention to, but that effect could be produced just as well inside the dialog. I still think the most pragmatic approach is (or similar):
|
@richardcrichardc yes I meant backdrop and yes it does not wrap modal(well in bootstrap 3 it actually does). |
Guys, I've just pushed a change that introduces If anyone could give this thing a try it would be awesome. |
Just tested it…and fixes my UC nicely (modal window sizing). |
Hi, Can anyone show me how to use the new feature to setup a different modal width than the default?
My class is setup as follows: Thank you, |
@chennoam7: I just went through a similar exercise for changing the width of a modal window. You might try changing your CSS to this: login-modal .modal-dialog {
width: 270px;
} |
@chennoam7 and anyone else who stumbles upon this seemingly unresolved thread - the resolution was the addition of Implementation as below worked for me and gave a class of var modalInstance = $modal.open({
templateUrl: 'myModalTemplate.html',
controller: this.ModalInstanceCtrl,
windowClass: 'full-screen',
resolve: {
items: function () {
return $scope.items;
}
}
}); |
Hey Guys, I'm really glad you added some extensibility here with the <div class="modal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
</div>
</div>
</div> Any chance of introducing one more option? @brianfeister Thanks for spelling it out for me, it's a long thread. |
I've just come across this after trying to do the same thing as @vanslly - and whilst @jeffjohnson9046's solution works it'd be easier to just allow using the classes bundled with Bootstrap instead of adding another snippet of CSS as a workaround. I'm happy to fork and submit a pull request if people think this is a good solution. |
.modal { width: auto; min-width: yourwidth; display: inline-block;} |
@vanslly there is a size option for modal $modal.open({
controller : 'myModalController',
size : 'lg',
...
}) |
I did read this #441 (comment) and it never really came to a satisfying conclusion.
The thing is, you won't be changing
template/modal/window.html
99% of time, what you might need to change quite often is its class.You might have 3 sets of modals for different cases, all with a different width. And since width is defined on the parent(
.modal
), how could do it?The
dialogClass
option as it was in the old $dialog made imho perfect sense.The text was updated successfully, but these errors were encountered: