How to check if element has class with AngularJS? - angularjs

I have an off panel menu working perfectly on a site. The user can open and close it using both a navicon or sliding it with the finger.
Right now I have a very nice navicon icon that transitions from Menu Icon to X Icon when is clicked (and opens the menu) and the other way around when is clicked again and the menu closes. Buuut if the user slides the menu open or closed instead of using the navicon, the transition is not triggered, which might lead to confusions on the UX (i.e. the menu being closed, and the navicon showing an X instead of the regular 3 horizontal lines icon).
So, the navicon has right now the following code to trigger the transition:
ng-click="open = !open" ng-class="{'open-mob':open}">
I thought that a nice and easy way to fix this, would be to trigger this "open = !open" every time that the menu is open or closed, as the js from the off panel adds the class slidRight to the main section when the menu is open, and removes it when it is closed.
Being so, is there some straight way to check if the class is there using AngularJS?
Something like if class = slidRight -> "open = !open".
Thanks!!

for those (including me) who could not get their head around Angular's documentation, here is an example which worked for me:
angular.element(myElement).hasClass('my-class');
angular.element(myElement).addClass('new-class');
angular.element(myElement).removeClass('old-class');
hope this help someone ...

Angular uses jqLite's .hasClass() natively.
Read here on the angular docs for more info.
http://docs.angularjs.org/api/angular.element
https://docs.angularjs.org/api/ng/function/angular.element

Related

Block scrolling when popover is opened

I'm not sure how to make the 'Popover' component of Material UI remain fixed on the screen when I open it. Because when I open the popover (https://mui.com/material-ui/react-popover/) It's not blocking the scroll and the box that appears after clicking is moving along the entire page. I don't want to keep the scroll bar visible while popover is open.
I'm using the latest version.
Image below
enter image description here
You can add overflow: hidden; to body element and remove it on close :) Tho its a weird behavior in docs as in source code there is no such thing, yet it happens

Suggestions for design approach to React app walkthrough

I'm about to try to create a walkthrough for a web app created using React. I'm trying to think of the best way to do it, and have been thinking of using things like Material UI's modal component. I'm thinking I should also include some kind of arrow component that points the user to whichever element (button, link, etc) on my page I want them to click next. Also I will want to create a backdrop to fade the screen except for whichever element I want the users attention to be drawn to.
I feel like this must have been done many times before, but I can't find anything from searching. Obviously whenever I Google "react walkthrough/guide/intro" I just get suggestions for teaching basic React.
(NB: I'm not looking to do one of those intro sliders, as I want to provide a more detailed step-by-step)
The keyword your need to search for is 'tour'. Searching on google for 'react tour', I found 2 libraries for you:
React Joyride: https://github.com/gilbarbara/react-joyride | Live Demo
reactour: https://github.com/elrumordelaluz/reactour | Live Demo
Both seem to have similar features:
Instruction modal that explains about an element on the page.
The modal is positioned next to the highlighted element.
The window will scroll down to the highlighted element if it's outside of the viewport.
The element is highlighted to bring more attention while the rest of the page is in the backdrop.
There are steppers on the modal to indicate which step you're on.

Accessibility issues when using Material-UI 'Menu' on top of a 'Drawer'

I was having an accessibility issue when using Material-UI with React. Specifically when placing a Menu on a Drawer. Essentially the normal behaviour of a Menu is to highlight the top MenuItem. This behaviour is different if that menu is placed on a Material UI Drawer.
I have recreated the problem here using just the example Material-UI Menu and Drawer:
https://codesandbox.io/s/material-ui-menu-and-drawer-accessibility-issues-xjj3h?file=/src/App.js
The following images show the difference between the two menus when opened. I am using the chromevox extension while testing:
A normal menu when using chromevox to show accessability:
A menu when it is placed on a material UI drawer:
Would anyone be able to point out if this is an error in my code or if perhaps there are any workarounds? Was going to raise this as a new github issue but felt it was worth asking the question here first. :)
By default, the drawer enforces (so long as it is open) that focus stays within itself. So when the menu opens and grabs focus, the drawer notices that it lost focus and it grabs it back.
There are two options for fixing this:
You can turn off this drawer behavior by specifying the disableEnforceFocus prop (example here).
You can specify the disablePortal prop on the menu (example here). This will cause the menu to be a descendant of the drawer in the DOM (by default the menu uses portals and is added as a child of the <body> element), so the drawer will not try to "take back" the focus, because when focus is in the menu it will still be within the drawer.
I would recommend option 2 since the drawer's focus enforcement is generally a good thing from an accessibility standpoint.

Polymer 1.0 paper-drawer-panel shadow and overlay

How can I make the paper-drawer-panel element behave like this site?
https://home-assistant.io/demo/
I want to be able to open and close the drawer panel even when the page is large. I also don't want there to be a drop shadow over the page when the drawer is out and the page is large, and I want the drawer to expand into the page and not overlay the "main".
I know about "forceNarrow" but it doesn't acheive what i want because it overlays the rest of the page when the drawer is active and it casts a drop shadow over the "main".
I just tested this on one of my sites with a drawer and, when I set forceNarrow to true and back again, I don't get a backdrop or anything, it is just as in the site you linked.
I am sure you know this, but for someone else stumbling on this the code would look something like this:
var drawer = document.getElementById('drawer');
drawer.forceNarrow = true;
drawer.forceNarrow = false;
Could you link to your site, or post some code here?
Edit: Here is an example

How to have the function of presentPage on onsen ui new version 1.1.4

The previous version of Onsen UI, there was a function call presentPage, so you could show a page without any characteristics of the previous page. It would clear the stack.
It was useful for examples, to be able to have just a page with a Sliding menu, but subsequent pages would not.
How can this in the latest Onsen UI (currently at v1.14)?
I tried using the resetToPage function, but that doesn't stop the Sliding menu.
Let me try to answer this one. I believe I understood the question :)
So, you have a "sliding menu" page with a main page, then a hidden menu page that could slide out when you swipe. Now you want a new page that show but doesn't have any sliding menu in it, just a regular page?
If so, you can achieve it by using ons-sliding-menu on top of an ons-nagivator
Take a look at this sample, I modified the sliding-menu code sample from onsen documentation: 'http://codepen.io/vnguyen972/pen/EjHDk'
Link to Page2 from the menu will open up a new page without any sliding menu in it.
Give + if this helps!
[1]: http://codepen.io/vnguyen972/pen/EjHDk

Resources