Change direction of Bootstrap Dropdown on React - css

I'm trying to display a navbar Dropdown to open to the left, but it keeps opening to the right. My dropdown is located at the far right of the navbar and when I open it, it opens to the right, going outside of the layout.
I've already tried the "pull-right" and "pull-left" solutions to no avail. Also the "dropdown-menu-right" and "dropdown-menu-left" solutions don't work.
html5
<ul className="nav navbar-nav navbar-right">
<li className="nav-item dropdown">
<a className="nav-link" id="walletOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src={require('../img/wallet.svg')} alt="easyfeedbacktoken" height="40px" />
</a>
<ul className="dropdown-menu" aria-labelledby="walletOptions">
<ImportMnemonicModal onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
<ShowMnemonic mnemonic = {this.props.mnemonic}/>
<DeleteWallet onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
</ul>
</li>
</ul>
I want the dropdown menu to drop to the left. It always drops to the right.

Try changing it from a dropDOWN to a dropLEFT.
That way it always opens to the left
Change :
<li className="nav-item dropdown">
To :
<li className="nav-item dropleft">
Complete code :
<ul className="nav navbar-nav navbar-right">
<li className="nav-item dropleft">
<a className="nav-link" id="walletOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<img src={require('../img/wallet.svg')} alt="easyfeedbacktoken" height="40px" />
</a>
<ul className="dropdown-menu" aria-labelledby="walletOptions">
<ImportMnemonicModal onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
<ShowMnemonic mnemonic = {this.props.mnemonic}/>
<DeleteWallet onUpdateMnemonic = {this.props.onUpdateMnemonic}/>
</ul>
</li>
</ul>
Source bootstrap (https://getbootstrap.com/docs/4.0/components/dropdowns/#dropleft-variation)

The Dropleft, Dropup and Dropright solutions didn't worked in my particular situation.
Neither the "pull-right" or "pull-left" solution.
I was able to force the Dropdown to drop into a specific coordinates using the following solution:
.nav .dropdown{
cursor: pointer;
position: absolute;
left: 88%;
top: 30%;
}
.dropdown-menu{
cursor: pointer;
position: absolute !important;
left: -8em;
top: 3em;
}
Making the dropdown button be in a specific position and the dropdown menu drop exactly how I wanted it to.
For Smaller devices, I just used #media and put another set of rules in order for the dropdown menu to work properly.

Related

Custom logo with link to homepage

I have a trouble to add custom logo with link to navbar if we scroll down
is class "dropdown-menu dropdown-inverse"
site: http://its-skin.upgates.com
CSS:
.secondlogo {
background-image: url(http://static.its-skin.upgates.com/m/m57daee4256187-sublogo.png);
width: 250px;
height: 54px;
margin-left: auto;
margin-right: auto;
}
here is the code full code :
<ul class="nav navbar-nav top-menu top-menu-categories">
{else}
<ul class="dropdown-menu dropdown-inverse" data-designer="d1-2-2-1">
{/if}
{foreach $tree as $category}
<li class="ct_{$category['category_id']} lev-{$level}{if $category['active']} active{/if}{if count($category['childs'])} dropdown{if $level > 1} dropdown-submenu{/if}{/if}" data-target-category="{$category['target_category_id']}">
<a href="{$category['url']}"{if $category["blank_yn"]} target="_blank"{/if} class="TopMenuLink">
{$category['name']}
{if (count($category['childs']))}
<i class="caret"></i>
{/if}
</a>
{if count($category['childs'])}
<button class="btn SubcategoriesLink"><i class="fa fa-chevron-right"></i></button>
{/if}
{include #desktopMenu tree => $category['childs'], level => $level + 1, option => false, colsCount => ceil(count($category['childs'])/$itemsInCol)}
</li>
{/foreach}
</ul>
You could add another list element at start of your ul which holds the link
<ul class="nav navbar-nav top-menu top-menu-categories">
<!-- New Element with class logolink -->
<li class="ct_29 lev-1 logolink">
<a href="http://its-skin.upgates.com/" class="TopMenuLink">
Link
</a>
</li>
<li class="ct_29 lev-1" data-target-category="29">
<a href="http://its-skin.upgates.com/krasa-it-s-skin" class="TopMenuLink">
Krása It's Skin
</a>
</li>
...
</ul>
Then just use css to put your logo in front of it
.logolink {
background-image: url(http://placehold.it/16x16/ff0000);
background-position: left center;
background-repeat: no-repeat;
padding-left: 20px; /* Adjust to your logo size*/
}
Example:
In case you want just a clickable logo image without text, wrap it inside the hyperlink <img src="#" /> and forget about the background-image in css.
EDIT:
If you want a fade-in effect when a user scrolls your page have a look at these two excellent jquery libraries which provide this functionality.
http://scrollmagic.io/
http://johnpolacek.github.io/scrollorama/
Alternative you can fade in with some jquery code. Therefore hide the logo (element) by setting it´s opacity to 0, detect the viewport scrolling and fade it in at some point. Find a working example here:
https://jsfiddle.net/mwtebtw9/1/
Code taken from: http://www.ordinarycoder.com/jquery-fade-content-scroll/

Why isn't my dropdown appearing?

Here is the fiddle
https://jsfiddle.net/r2zmxzzd/
As you can see, the dropdown in the top menu "Alumni" is working but the dropdown in the lower menu i.e. "About UET" is not working.
I've been staring at the code for more than 2 hours but still can't get that damn dropdown to appear. I've tried inspecting the elements. The dropdown appears in the DOM as active but still doesn't show up.
Here is the code of the dropdown
<ul class="nav navbar-nav navbar-right">
<li class="dropdown primaryNavItem">
About UET <span class="caret"></span>
<ul class="dropdown-menu">
<li>Historic Profile</li>
<li>Vision & Mission</li>
<li>Development Projects</li>
<li>Core Team Members</li>
<li>UET Progress Report 2015</li>
<li>Student Teacher Ratio</li>
<li>Information</li>
<li>Faculty Statistics</li>
<li>FAQs</li>
<li>Budget</li>
<li>External Linkages</li>
<li>International Funding</li>
<li>Spin off companies</li>
<li>Progress Profile</li>
<li>Site map</li>
<li>Contacts List</li>
</ul>
</li>
</ul>
Can anyone please tell me why the lower dropdown isn't appearing?
Thanks in advance.
You have this
header {
overflow: hidden;
height: 135px;
}
and the dropdown is behind. Remove overflow:hidden
You have to use:
header {
overflow: visible;}
Your <header> has an overflow: hidden css property. That's causing the dropdown to be clipped out of view.
Remove overflow: hidden from your header: https://jsfiddle.net/r2zmxzzd/1/
Hi your dropdown is working fine but you have to change css on headersee screenshot
Thanks
It's because you're using an a tag:
About UET <span class="caret"></span>
Should be:
<button type="button" class="primaryNavLink dropdown-toggle" data-toggle="dropdown">About UET <span class="caret"></span></button>
And then style as appropriate

how to remove the padding in dropdown-menu list <a>?

<ul class="nav navbar-nav pull-right" style="margin-right: 25px;" >
<li> My Profile </li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
My Blog <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>Sports</li>
<li class="divider"></li>
<li>Foods</li>
<li class="divider"></li>
<li>Entertainment</li>
<li class="divider"></li>
<li>Travel</li>
</ul>
</li>
how to delete the padding on my dropdown-menu list because its destroying the background color i put in there. This is the image of my current dropdown-list which having some problem on padding:
Here are few things
Incorrect html structure
<li>Foods</li>
change it to
<li>Foods</li>
show us the style for li, a and .divider
which one is using background: #809109;
I guess you need to remove padding of li
.dropdown-menu > li{
padding:0px
}
or you can add background-color for li too
.dropdown-menu > li{
background-color:#809109;
}
Though the problem statement is incomplete and the html syntax is faulty, still this problem can occur without those. The problem lies in inserting the divider or horizontal rule, whatever separator you are using. For these, the Unordered List tag adds additional padding which might be the case in this problem. You can use one of the methods mentioned in this answer to solve your problem:
Remove padding from unordered list

angular-bootstrap dropdown on mouseenter and keep dropdown-menu from hiding before being clicked.

First, I'm aware of this posts:
Activating bootstrap dropdown menu on hover
Bootstrap Dropdown with Hover
How to make twitter bootstrap menu dropdown on hover rather than click
And others, but still not found the correct solution yet, here's what I did so far.
first I used the is-open attribute from the angular-bootstrap dropdown directive like this:
<span class="dropdown" dropdown is-open="status.isopen">
<a
href
class="dropdown-toggle"
ng-mouseenter="status.isopen = true"
ng-mouseleave="status.isopen = false"
>
hover me for a dropdown with angular-bootstrap
</a>
<ul
class="dropdown-menu"
>
<li ng-repeat="choice in items">
<a href>{{choice}}</a>
</li>
</ul>
</span>
that seemed to work but 2 bugs appeared:
the first is when dropdown-toggle element is clicked the dropdown menu is gone clicking again wont bring it back you have to mouseleave then mouse enter the dropdown-tooggle to get the dropdown-menu back.
the second is a css/html problem.
Usually the regular css solution for a dropdown is like this:
<a class="css-dropdown">
hover here with css.
<div class="css-dropdown-menu">
<p>item 1</p>
<p>item 2</p>
<p>item 3</p>
</div>
</a>
Notice the dropdown-menu now is inside the dropdown-toggle element which mean when moving with the mouse from the dropdown-toggle to the dropdown-menu it's moving from parent to child, so basically we still hovering over the dropdown-toggle since we are in it's child, which mean the dropdown-menu will still be visible, on other hand, the bootstrap dropdown works with the click event so having the dropdown-menu as a child of the dropdown-toggle is not needed, but now when someone wants to change the behavior to mouseenter/hover once the mouse leaves the dropdown-toggle the dropdown-menu disappear so we no longer have access to the dropdown-menu elements this is visible in this plunker
To fix the first bug, I just removed the dropdown directive then replaced the is-open with ng-class directive like this.
Change this:
<span class="dropdown" dropdown is-open="status.isopen">
to this:
<span class="dropdown" ng-class="{'open': status.isopen}">
The rest stays the same plunker that fixed the first bug.
The second bug is tricky, since the dropdown-menu is no longer a child of the dropdown-toggle the hover effect wont last while moving from the toggle to the menu, so I did this.
Changed this:
<ul class="dropdown-menu">
to this:
<ul
class="dropdown-menu"
ng-mouseenter="status.isopen = true"
ng-mouseleave="status.isopen = false"
>
That did it but another bug appeared when clicking the dropdown-menu item it stays open, so I kept hacking by doing this.
changed this:
<li ng-repeat="choice in items">
to this:
<li ng-repeat="choice in items" ng-click="status.isopen = false">
That give me the required behavior plunker.
That said, this is not a good solution since a lot of directives are involved here for a simple visual effect, the last plunker I provided contains a css solution with no Bootstrap or AngularJS involved, though it is the required behavior it is not the required html structure or visual result, what I need is to have a space between the dropdown-toggle and the dropdown-menu not a padding of the toggle element just an empty space, which make the css solution not valid in this situation.
So, my question is there a better way of doing this without adding a new plugin/library more clean and easily reusable solution for the hover drop down menu?
First, have the toggling on the top-most parent element (in this case, the <span>)
<span class="btn-group" dropdown is-open="status.isopen" ng-mouseenter="status.isopen = true" ng-mouseleave="status.isopen = false">
<a class="btn btn-primary dropdown-toggle" dropdown-toggle>
Button dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</span>
This will allow the behavior you wanted - while still allowing clicking to show/hide the menu ;-)
However there's an annoyance: if you move the mouse cursor slower and pass the small gap between the toggle and menu, it will hide the menu.
So secondly, add a small CSS to remove the gap
.dropdown-menu {
margin-top: 0;
}
See the action in this plunker.
I know you want a solution without adding a new plugin/library, but you (or others seeking for this behavior) might want to try using No Close from Dropdown Enhancements lib to keep the dropdown open even after clicking in one of its options:
Do not close the menu on click on radio add class .noclose.
<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">
Checked option <span class="caret"></span>
</button>
<ul class="dropdown-menu noclose">
<li>
<input type="radio" id="gr1_1" name="gr1" value="1">
<label for="gr1_1">Option 1</label>
</li>
<li>
<input type="radio" id="gr1_2" name="gr1" value="2">
<label for="gr1_2">Option 2</label>
</li>
<li>
<input type="radio" id="gr1_3" name="gr1" value="3">
<label for="gr1_3">Option 3</label>
</li>
</ul>
</div>
Also add a CSS solution for the hovering problem:
.btn-group:hover .dropdown-menu.noclose {
display: block;
}
.dropdown-menu.noclose {
margin-top: 0px;
}
And, of course, don't forget to import the libs:
<script src="./js/dropdowns-enhancement.min.js"></script>
<link href="./css/dropdowns-enhancement.css" rel="stylesheet"\>
In your case I suggest you to study the Dropdown Enhancements's source code to see how it works and maybe find a more suitable solution.
Try adding this line to your css:
.btn-group:hover>.dropdown-menu { display: block; margin-top: 0; }
You'll have to remove your is-open, ng-mouseenter and ng-mouseleave directives.
Below is the solution I came up with, while working on the same issue.
I used a simple custom directive that:
binds the mouseenter and mouseleave events to the dropdown in order correctly to show/hide the menu.
dynamically adds a custom CSS class to the dropdown menu in order to prevent the menu from disappearing when moving the cursor from the button to the menu. Note that this solution has the advantage of not removing the visual gap between the button and menu.
prevents the menu from disappearing when the button is clicked.
The CSS rule uses a before pseudo-element to fill the gap between the button and the menu. I added the border property which can be uncommented to easily get a visual feedback.
.dropdown-hover-menu::before {
content: '';
position: absolute;
left: 0;
width: 100%;
top: -3px;
height: 3px;
/*border: 1px solid black;*/
}
The HTML structure of the snippet is based on the available examples in the dropdown section of the angular-ui bootstrap documentation
angular.module('app', ['ui.bootstrap'])
.directive('dropdownHover', function() {
return {
require: 'uibDropdown',
link: function(scope, element, attrs, dropdownCtrl) {
var menu = angular.element(element[0].querySelector('.dropdown-menu')),
button = angular.element(element[0].querySelector('.dropdown-toggle'));
menu.addClass('dropdown-hover-menu');
element.bind('mouseenter', onMouseenter);
element.bind('mouseleave', onMouseleave);
button.bind('click', onClick);
function openDropdown(open) {
scope.$apply(function() {
dropdownCtrl.toggle(open);
});
}
function onMouseenter(event) {
if (!element.hasClass('disabled') && !attrs.disabled) {
openDropdown(true);
}
};
function onMouseleave(event) {
openDropdown(false);
};
function onClick(event) {
event.stopPropagation();
}
scope.$on('$destroy', function() {
element.unbind('mouseenter', onMouseenter);
element.unbind('mouseleave', onMouseleave);
button.unbind('click', onClick);
});
}
};
});
.dropdown-hover-menu::before {
content: '';
position: absolute;
left: 0;
width: 100%;
top: -3px;
height: 3px;
/*border: 1px solid black;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.3.3/ui-bootstrap-tpls.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div ng-app="app">
<div class="btn-group" uib-dropdown dropdown-hover>
<button type="button" class="btn btn-primary dropdown-toggle">
Button dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu role="menu">
<li role="menuitem">Action
</li>
<li role="menuitem">Another action
</li>
<li role="menuitem">Something else here
</li>
<li class="divider"></li>
<li role="menuitem">Separated link
</li>
</ul>
</div>
</div>

How to click on an hidden drop down menu element using webdriver, which is not a select

I want to click on delete which is in the sub menu.
I tried the below code, but nothing happens.
wd_handle.execute_script("document.getElementById('optionPanel').hidden=false;")
mouse.move_to_element(OptionPanel).perform()
WebDriverWait(wd_handle,10)
wd_handle.find_element_by_partial_link_text('Delete').click()
HTML Source:
<div id="optionPanel" style="height: auto; width: auto; left: 126px; top: 368px; display: none; overflow-y: hidden;">'
<div class="wrapper">
<ul aria-hidden="false" role="menu">
<li role="menuitem">
<li role="menuitem">
<li class="divider" role="menuitem">
<a class="optionPanelLink" tabindex="0"
href="#playlistManager/action=delete/selected=701f55af-c5f0-4f31-b34f-964f52be5fef/idx=0">
Delete</a>
</li>
</ul>
</div>
</div>
I have to click on the element with id = 7ba9b231-5fc4-448b-b41a-f236437c182cCount to make the above elements visible.
<li class="playlist viewing">
<a id="7ba9b231-5fc4-448b-b41a-f236437c182cLink" class="ellipsis" title="TestList2" href="#playList/name=TestList2/list=7ba9b231-5fc4-448b-b41a-f236437c182c">TestList2</a>
<span class="entryCount">0</span>
<a id="7ba9b231-5fc4-448b-b41a-f236437c182cCount" class="customPlaylistSpriteLocation optionSprite" href="#option/playlist=TestList2/selected=7ba9b231-5fc4-448b-b41a-f236437c182c/idx=0"></a>
</li>
You can click on the hidden menu item using xpath
import org.openqa.selenium.interactions.Actions;
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("Enter Menu here"))).build().perform();
builder.moveToElement(driver.findElement(By.xpath("Enter Target here"))).build().perform();
driver.findElement(By.xpath("Enter Target here")).click()
Hope this is code do
Are you sure that your find_element_by_partial_link_text('Delete') works and return an element ?
If it really doesn't work i suggest to use the cssSelector like : "li.divider a"
Tell me what's up.
Replace:
wd_handle.execute_script("document.getElementById('optionPanel').hidden=false;")
With:
wd_handle.execute_script("document.getElementById('optionPanel').style.display='block';")
If it doesn't work, then try using both of them (one after another)...
First of all check your submenu item in which place delete button is highlighted......by using hover.And take that as a reference w.r.t id you can click delete button...here is a code
WebElement wb=driver.findElement(By.xpath("//li[#datapostid='52f377a10a1de86e33f9bc90']/div"));
Actions act=new Actions(driver);
act.moveToElement(wb);
act.perform();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
wb.findElement(By.cssSelector("span.commdelete")).click();

Resources