Skip to content

feat(offCanvas): add closeOnClick attribute to prevent hiding #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/offcanvas/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1 class="title">OffCanvas</h1>
</nav>

<aside class="left-off-canvas-menu">
<ul class="off-canvas-list">
<ul class="off-canvas-list" close-on-click="false">
<li><a href="#">Left Sidebar</a></li>
</ul>
</aside>
Expand Down
3 changes: 2 additions & 1 deletion src/offcanvas/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The off canvas module expects the use of several nested elements with the follow
- `left-off-canvas-toggle`: Wraps the left off canvas menu.
- `right-off-canvas-toggle`: Wraps the right off canvas menu.
- `exit-off-canvas`: Occludes the main page content when an off canvas menu is visible. Hides the menu when clicked.
- `off-canvas-list`: Contains off canvas menu items. Hides the menu after a nested link is clicked.
- `off-canvas-list`: Contains off canvas menu items.
- At default the menu hides after a nested link is clicked. Set the `close-on-click` attribute to false to prevent this action. You can reference a scope variable, too.

See the demo page for example on how to use this and see the [Foundation docs](http://foundation.zurb.com/docs/components/offcanvas.html) for more details.
7 changes: 6 additions & 1 deletion src/offcanvas/offcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ angular.module("mm.foundation.offcanvas", [])
}])
.directive('offCanvasList', [function () {
return {
scope: {
closeOnClick: "="
},
require: '^offCanvasWrap',
restrict: 'C',
link: function ($scope, element, attrs, offCanvasWrap) {
element.on('click', function () {
offCanvasWrap.hide();
if ($scope.closeOnClick !== false) {
offCanvasWrap.hide();
}
});
}
};
Expand Down
9 changes: 8 additions & 1 deletion src/offcanvas/test/offcanvas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('offcanvas directive', function () {
'</section>' +
'</nav>' +
'<aside class="left-off-canvas-menu">' +
'<ul class="off-canvas-list">' +
'<ul class="off-canvas-list" close-on-click="false">' +
'<li><a href="#">Left Sidebar</a></li>' +
'</ul>' +
'</aside>' +
Expand Down Expand Up @@ -78,4 +78,11 @@ describe('offcanvas directive', function () {
expect(element).isClosed();
});

it('does not close after clicking on a list item with close-on-click=false', function() {
$('.left-off-canvas-toggle', element).trigger('click');
expect(element).leftOpen();
$('.left-off-canvas-menu > .off-canvas-list', element).trigger('click');
expect(element).leftOpen();
});

});