How to have a div rather than a button for pivot link - office-ui-fabric

I want to customize a PivotItem to make it close-able (kind of like browser tabs).
I provided a custom onRenderItemLink implementation do display an X icon on the right side of the tab, and an onClick method on that icon that will close the tab.
The main issue I'm facing is that this PivotItem is wrapped with a button (Pivot.Base.tsx renders a Commandbutton), that intercepts all onClick events on Firefox.
Firefox does not allow onClick events under a Button (this seems to be in accordance with the standard, so it's not considered a bug), so i can never close a tab on Firefox.
Is there any way to force Fabric UI to create a div rather than a button in this scenario?
Is there any other way to force a div there (some way to intercept what fabric ui creates and switch the button with a div)?
Advice appreciated.

Ended up closing the tab if the button was clicked on its right side
const clickX = clickEvent.pageX;
const buttonRight = clickEvent.currentTarget.offsetLeft + clickEvent.currentTarget.offsetWidth ;
if (buttonRight - clickX <= 40) {
removeTab(tab);
}

Related

How do i remove the href on popup's close button in Leaflet?

In a Vue app, the close button on the markers popup change the URL by adding #close, making the page change.
Can I remove it?
Marker popup example
I recommended you to read leaflet doc for marker
you will see that you can hide button close by set option closeButton: false

Custom context menu XAML for WP8

I try to implement a custom ContextMenu in a LongListSelector.
I'm not using the ContextMenu from Microsoft.Phone.Controls.Toolkit, it's basically the same as in the Rowi App:
(source: hiddenpineapple.com)
Approach 1
My list item toggles a VisualState on hold and an overlay is shown with controls in it.
The problem
I can't find a way to go back to the default state when the user clicks outside of the list item (as in the default ContextMenu).
Approach 2
I've implemented a custom template for the toolkit ContextMenu which looks exactly the same. I had to move its margin top to -itemHeight, as by default it is below the item.
The problem
The problem with this solution is, that it automatically closes itself when opening and I couldn't figure out how to avoid this.
Another problem was that it didn't work well with TiltEffect.IsTiltEnabled from the Toolkit (visual problems).
I need your help
Any suggestions on how to get this working?
Answer
Thanks to Cheese, now I know how to properly close the menu when the user clicks outside.
His suggestion was to get the coordinates of a Tap event on the current page, and check if it's inside the menu. When not, close the menu.
So I added a Tap listener to the page when the menu opens, and removed it when the menu closes. From the page listener I got the event coordinates and could check if it's inside the control which holds the menu (same size and position). I received the position of the control with Point leftUpperPoint = control.TransformToVisual(page).Transform(new Point(0, 0)) and the rightLowerPoint by adding the ActualWidth and ActualHeight.
But then I realized:
Why should I even calculate if the tap is inside the menu? I always want to close the menu when the user taps anywhere on the screen. If it's outside, yes. If it's on a menu button, yes.
Another modification I made was to listen for MouseLeftButtonDown instead of Tap as it also triggers when the user swipes.
So I removed this code and came up with the following:
private void ToggleMenu(object sender, System.Windows.Input.GestureEventArgs e)
{
PhoneApplicationFrame frame = ((PhoneApplicationFrame)Application.Current.RootVisual);
VisualState state = this.States.CurrentState;
if (state == null || state.Name == "DefaultState")
{
frame.MouseLeftButtonDown += MouseDownDelegate;
this.State = "MenuState";
}
else
{
frame.MouseLeftButtonDown -= MouseDownDelegate;
this.State = "DefaultState";
}
}
private void MouseDownDelegate(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToggleMenu(sender, null);
}
This works perfectly!
Thanks to Cheese for the hint.
Something like this by #denniscode http://dotnet.dzone.com/articles/rowi-show-tap-menu
Approach 1 problem
The best solution would be:
Get the menus coordinates, when user makes a tap - you check are tap coordinates on menu or not, if not - dissmiss - simple.
Approach 2 problem
I guess you had some button in a corner and when you tapped on it - nothing happened? And when you dissmissed the Tilt all worked. It seems that tilt works faster than a click, so, tilt changes the button coordinates, and device thiks you have missed/or dragged off
You can use what #ScottIsAFool suggested and maybe create another Dependency Property on your TapMenu control of type UIElement named CloseWhenTappedElement and automatically listen for Tap events inside your control once set. For example
<Grid x:Name="TapArea"/>
<TapMenu CloseWhenTappedElement="{Binding ElementName=TapArea"}/>

Can a dojo TabContainer be configured to switch by mouse over?

I'm using dojo toolkit dijit.layout.TabContainer to switch 3 tabbed pages.
Right now I click on tabs to switch them, but I want to switch them by mouse over instead.
Can a TabContainer be configured to switch by mouse over, or should I write a code to handle mouse over events to explicitly switch tabs?
I'd appreciate any suggestions!
-Sari
Yes. For this functionality, we need to add the onmouseover event to the tabs label fields. Add this code inside the dojo/ready (or addOnLoad) function.
require(["dojo/ready","dojo/query"], function(ready,query){
ready(function(){
var tabs = dijit.byId("TabContainerID");
query("#TabContainerID.dijitTabInner").onmouseover(function(evt){
var tablabelid = dijit.getEnclosingWidget(evt.target).id;
var currentId = dijit.byId("TabContainerID").selectedChildWidget;
var tabwidid = tablabelid.split("_").pop();
if(tabwidid && currentId!=tabwidid) {
tabs.selectChild(tabwidid);
}
});
});
});

Dojo emit click event to dojox.mobile.ToolBarButton

Im trying to fire a click event on a tool bar button Dojo 1.8.1.
<div data-dojo-type="dojox.mobile.ToolBarButton" class="backButton" moveTo="cartView" transition="slide">
I have tried
function backClick(){
var backButton = dojo.query(".backButton", dojo.byId(currentView.id))[0];
writeLog("backClick::"+backButton);
if(backButton){
var backDijit = dijit.registry.byId(backButton.id);
writeLog("backDijit::" + backDijit.id);
writeLog("emit Click");
backDijit.emit("click", {bubbles:true});
writeLog("emit mousedown");
backDijit.emit("mousedown",{bubbles:true});
writeLog("emit mouseup");
backDijit.emit("mouseup",{bubbles:true});
writeLog("touchstart");
backDijit.emit("touchstart");
writeLog("touchEnd");
backDijit.emit("touchend");
}else{
//Exit App notification
navigator.app.exitApp();
}
}
mousedown/mouseup combo works on the browser.
But on the device it does not work(Android). What is the event that i have to send to 'click' the button on a device?
It seems that the sequence of events that will activate the toolbar button 'click' on a touch device is touchstart followed by touchend.
I suppose that your example do not work because the synthetic touch events that you are emitting do not contains any data, which fails the different methods that handle it.
Another way to trigger the click handler of the toolbar button would be to call its _onClick method.

Windows 8 appbar on selected item (like startup screen)

What I want to achieve in my application is the same as what windows did on their start up screen. When you select an item, open the appbar and show more items. When you just open te appbar when not selecting anything, don't show those items.
So far so good and it works like I want it to be. But there is some issue I can't solve. When you select an item on the start up screen, you can't close te appbar when right clicking anywhere on the screen. You have to deselect the item.
I just can't figure out how to disable that right click to close the appbar. Because then I am in a state where I have a selected item, but no appbar. I don't want that...
Thanks in advance!
There is a property called IsSticky
this can be used to stop you appbar from collapsing.
the other option you have is to hooking into Closed event and force it to re-open.
Based on the screen you provided aka the Metro UI :) i'd say that create a page that just hosts other tiles.
I have done a similar thing in one of my apps, have a look at
http://apps.microsoft.com/windows/en-gb/app/cineworld/7adfde16-33c3-4b51-b758-00366325288d
Have a look at Coding4Fun or Callisto
Set the AppBar property IsSticky="true" and handle the event RightTapped on your GridView/ListView, and in the event handler set e.Handled = true;
This will stop the rightclick/swipe routed event from reaching Page and it won't close the AppBar.
You could override the hide() function of the appbar and replace it with something like this:
appBar.hide = function () {
/// <signature helpKeyword="WinJS.UI.AppBar.hide">
/// <summary locid="WinJS.UI.AppBar.hide">
/// Hides the AppBar, if visible, regardless of other state
/// </summary>
/// </signature>
// Just wrap the private one
var listView = document.getElementById("yourListView").winControl;
var count = listView.selection.count();
if(count <1)
this._hide();
}
It's not a great workaround, but it works like a charm :)