Overlay button on button in Material UI - reactjs

Currently I'm trying to overlay a button on another button in Material UI:
https://codesandbox.io/s/responsivedrawer-demo-material-ui-forked-inc7xz?file=/demo.js
I'd like if pressing the X would only print B, rather than printing A and B. I know nesting buttons is not the correct way to do it, but I'd like to overlay the button with the exact look and ripple behavior I'm currently seeing with the nesting. I like how it looks so well aligned on the right, clicking the X doesn't ripple the effect to the entire ListButton the ListButtons takes up the entire drawer width without any extra work, and clicking the ListButton ripples under the X.
I'd really appreciate it if someone has the time to help. Thanks so much!

The solution would be to stopPropagation inside the onClick function since this is where the click event happens.
onClick={(e) => {
e.stopPropagation();
console.log("B");
}}

Related

Ant D Drawer , mask={false} and maskClosable={true} incompatible?

I am using the ant d Drawer component as a pop up modal. I wanted to disable the mask as I didnt want the dark mask it applies to the left hand side, however this seems to prevent the component from mantaining its mask closable parameter which allows you to close the modal by clicking on the left side of the screen (mask)
A possible solution would be to mantain the mask param as true but change the css styling so its completely transparent but I am not sure how to do this?
Any other solutions are welcomed
Thanks in advance
<div>
<Drawer
className="add-days-modal"
placement="right"
closable={false}
onClose={props.handleCancel}
visible={props.addDayModalVisible}
key="right"
width="500px"
maskClosable={true}
mask={false}
>
{props.content}
</Drawer>
</div>
Without the mask there is nothing for the user to click on which would trigger the close event.
What you can try doing instead to achieve what you are after is set the opacity on the mask to 0, this will mean that it is invisible to the user but they can still click on it which will close the Drawer.
The other option which is much more complex is to add an event handler to the screen click. Then when the user clicks anywhere away from the draw you set the state of the Drawer to closed.
My advice is go with option 1

How can I make a blur background that appears onPress of a button and when clicking back on the background it un-blurs it?

I also want to when I click on the background and there are other pressable things/buttons on this background, they are not being pressed unless the state is back to when it is un-blurred (basically: only the blurred background can be pressed when the screen is blurred). If you need an example look at twitter mobile: when you click on the post (+) button, it blurs the background but when clicked back it un-blurs it. (Must work for IOS and Android).
I think you need this..
In CSS create 2 classes - First one with the blur and second one without.
In React create 2 functions - 1 onclick for the blur-button and 1 onclick for the close button. These functions should change the class of body.
$('.button').click(function(){
$('body').addClass('blur'); });

KeyboardAvoidingView Issue With TextInput and Animated.API

I designed a page and I have a Flatlist and I have pickers, slider and text input in this page. I also used Animated View in this page and I have an issue with KeyboardAvoidingView.
The design looks like this when the page is first rendered:First Render
When user click "Add" Icon the page looks like this:
Animation Triggered and View Flex Grow
And here is my main issue. When user click the TextInput for type something. This page looks like this:
TextInput Focused
You can also see my render code in this photo.JSX Code
I tried placing "keyboardavoidingview" in different places but my problem was not solved. How can I solve this?
P.S: The animation value based on "flex" property. The view has "0.5" flex value on first start and When the button is clicked, it takes the value "1".
wrap your code inside
<KeyboardAvoidingView>
</KeyboardAvoidingView>
And give it a style like this
flex: 1,
behavior="padding"
Kolay gelsin :)

React-router clickable elements inside Link

I've got a following element inside <Link> component:
It needs to be whole clickable and it needs to preserve cmd/ctrl + click functionality (also right mouse button + open in new tab). The problem is that I need to enable clicking also on times icon without transition to a new location. Is it somehow possible?
The problem is that the onClick event on the times icon is triggering the parent onClick which is the Link component which is the default behavior.
To prevent this you should add e.preventDefault() in your function:
onClick={(e) => e.preventDefault()}
Note: It might also be a good idea to use e.stopPropagation(); alongside e.preventDefault();

In Angular, Is it possible to have one trigger for a tooltip to appear, and another for it to disappear?

So I have a button on my template, with a tooltip that gives some extra information about the button. I would like the tooltip to appear when the mouse hovers over the button, and then disappear when the button is clicked. Clicking the button loads a separate view.
Currently I have it so the tooltip appears on hover, but then the problem is that the tooltip sticks around after the button has been clicked. Since the button is no longer part of the current view, the tooltip jumps to the top corner of the screen for a few seconds before disappearing. I'd like it to disappear the moment the button is clicked.
So far I've tried two things to solve the problem, neither of which have worked:
I tried wrapping the JS function which opens a new view in $timeout, hoping that the tooltip would disappear before the new view loads.
I tried changing the tooltip-trigger to 'click', but now the tooltip won't appear when the mouse is hovering over it. It will appear once the button is clicked, and stay there until the view is re-loaded.
Here is my code, which includes the two failed attempts mentioned above:
Test.html:
<a class="the-button" ng-click="loadNewView($event)"
uib-tooltip-html="getToolTipInfo($event)"
tooltip-trigger="'click'"
>
Click Me!
</a>
Test.js:
ctrl.loadNewView = function($event) {
$timeout(function($event) { //timeout
SystemViews.openNewView(ctrl.newView);
});
};
Is it possible to have separate triggers for a tooltip like this? If not, what is another way that I can make sure the tooltip disappears before the new view is loaded?
Thank you very much in advance for any wisdom you'd be willing to impart.
The simplest solution is to hide the tooltip before changing view.
If your tooltip is triggered by a click on your anchor, you can emulate a click in your loadNewFunction function to hide it.
Test.html:
<a id="the-button" ng-click="loadNewView($event)" uib-tooltip-html="getToolTipInfo($event)" tooltip-trigger="'click'">Click Me!</a>
Test.js
ctrl.loadNewView = function($event) {
angular.element('#the-button').trigger('click');
SystemViews.openNewView(ctrl.newView);
};
Maybe this answer can interest you since it's about a very similar question.
I found the solution (for me, at least). I learned that you can have multiple triggers if you separate them by space. For my solution, I used the value:
tooltip-trigger='mouseenter click'.
That way it always turns on when I mouse-over, and turns off when I click.
Test.html:
<a class="the-button" ng-click="loadNewView($event)"
uib-tooltip-html="getToolTipInfo()"
tooltip-trigger="'mouseenter click'
>
Click Me!
</a>
Test.js:
ctrl.loadNewView = function() {
SystemViews.openNewView(ctrl.newView);
};
Hope someone else finds this helpful!

Resources