Skip to content
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

docs(dropdown): decompose manual triggering demo #4116

Merged
merged 4 commits into from
Apr 24, 2018
Merged
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: 2 additions & 0 deletions demo/src/app/components/+dropdown/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { DemoDropdownStateChangeEventComponent } from './state-change-event/stat
import { DemoDropdownAutoCloseComponent } from './autoclose/autoclose';
import { DemoDropdownCustomHtmlComponent } from './custom-html/custom-html';
import { DemoAccessibilityComponent } from './accessibility/accessibility';
import { DemoDropdownByIsOpenPropComponent } from './trigger-by-isopen-property/trigger-by-isopen-property';

export const DEMO_COMPONENTS = [
DemoDropdownBasicComponent,
Expand All @@ -27,6 +28,7 @@ export const DEMO_COMPONENTS = [
DemoDropdownDropupComponent,
DemoDropdownMenuDividersComponent,
DemoDropdownTriggersManualComponent,
DemoDropdownByIsOpenPropComponent,
DemoDropdownDisabledComponent,
DemoDropdownDisabledItemComponent,
DemoDropdownAlignmentComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="btn-group" dropdown #dropdown="bs-dropdown" [autoClose]="false">
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">
Button dropdown <span class="caret"></span>
</button>
<ul *dropdownMenu class="dropdown-menu" role="menu">
<li role="menuitem"><a class="dropdown-item" href="#">Action</a></li>
<li role="menuitem"><a class="dropdown-item" href="#">Another action</a>
</li>
<li role="menuitem"><a class="dropdown-item" href="#">Something else
here</a></li>
</ul>
</div>
<button type="button" class="btn btn-primary" (click)="dropdown.isOpen = !dropdown.isOpen">Toggle</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-dropdown-trigger-by-isopen',
templateUrl: './trigger-by-isopen-property.html'
})
export class DemoDropdownByIsOpenPropComponent {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div class="btn-group" dropdown #dropdown="bs-dropdown" [autoClose]="false" [isOpen]="status.isopen" (isOpenChange)="change($event)" placement="top">
<button id="button-triggers-manual" dropdownToggle type="button" class="btn btn-primary dropdown-toggle"
aria-controls="dropdown-triggers-manual">
<div class="btn-group" dropdown #dropdown="bs-dropdown" [autoClose]="false">
<button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">
Button dropdown <span class="caret"></span>
</button>
<ul id="dropdown-triggers-manual" *dropdownMenu class="dropdown-menu"
Expand All @@ -11,10 +10,8 @@
<li role="menuitem"><a class="dropdown-item" href="#">Something else
here</a></li>
<li class="divider dropdown-divider"></li>
<li role="menuitem"><a class="dropdown-item" href="#">Separated link</a>
</li>
</ul>
</div>
<button type="button" class="btn btn-primary" (click)="toggleDropdown($event)">Toggle</button>
<button type="button" class="btn btn-info" (click)="dropdown.show()">Show</button>
<button type="button" class="btn btn-info" (click)="dropdown.hide()">Hide</button>
<button type="button" class="btn btn-primary" (click)="dropdown.toggle(true)">Toggle</button>
<button type="button" class="btn btn-primary" (click)="dropdown.show()">Show</button>
<button type="button" class="btn btn-primary" (click)="dropdown.hide()">Hide</button>
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,4 @@ import { Component } from '@angular/core';
templateUrl: './triggers-manual.html'
})
export class DemoDropdownTriggersManualComponent {
status: { isopen: boolean } = { isopen: false };

toggleDropdown($event: MouseEvent): void {
$event.preventDefault();
$event.stopPropagation();
this.status.isopen = !this.status.isopen;
}

change(value: boolean): void {
this.status.isopen = value;
}
}
22 changes: 16 additions & 6 deletions demo/src/app/components/+dropdown/dropdown-section.list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DemoDropdownBasicComponent } from './demos/basic/basic';
import { DemoDropdownBasicLinkComponent } from './demos/basic/basic-link';
import { DemoDropdownSplitComponent } from './demos/split/split';
import { DemoDropdownTriggersManualComponent } from './demos/triggers-manual/triggers-manual';
import { DemoDropdownByIsOpenPropComponent } from './demos/trigger-by-isopen-property/trigger-by-isopen-property';
import { DemoDropdownDisabledComponent } from './demos/disabled-menu/disabled-menu';
import { DemoDropdownDisabledItemComponent } from './demos/disabled-item/disabled-item';
import { DemoDropdownAlignmentComponent } from './demos/alignment/menu-alignment';
Expand Down Expand Up @@ -72,17 +73,26 @@ export const demoComponentContent: ContentSection[] = [
outlet: DemoDropdownSplitComponent
},
{
title: 'Manual triggers',
title: 'Manual triggering',
anchor: 'triggers-manual',
component: require('!!raw-loader?lang=typescript!./demos/triggers-manual/triggers-manual.ts'),
html: require('!!raw-loader?lang=markup!./demos/triggers-manual/triggers-manual.html'),
description: `<p>Dropdown can be triggered in two ways:
<ul>
<li>by toggling <code>isOpen</code> property</li>
<li>by <code>show</code>/<code>hide</code> methods from directive</li>
</ul></p>`,
description: `<p>Dropdown can be triggered by <code>show</code>, <code>hide</code> and
<code>toggle</code> methods from directive
<br>
Use method <code>toggle(true)</code> if you want to toggle the dropdown or <code>toggle(false)</code>
if you want to only close opened dropdown.
</p>`,
outlet: DemoDropdownTriggersManualComponent
},
{
title: 'Trigger by isOpen property',
anchor: 'trigger-by-isopen-property',
component: require('!!raw-loader?lang=typescript!./demos/trigger-by-isopen-property/trigger-by-isopen-property.ts'),
html: require('!!raw-loader?lang=markup!./demos/trigger-by-isopen-property/trigger-by-isopen-property.html'),
description: `<p>Dropdown can be shown or hidden by changing <code>isOpen</code> input property</p>`,
outlet: DemoDropdownByIsOpenPropComponent
},
{
title: 'Disabled menu',
anchor: 'disabled-menu',
Expand Down
2 changes: 1 addition & 1 deletion demo/src/ng-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ export const ngdoc: any = {
},
{
"name": "toggle",
"description": "<p>Toggles an element’s popover. This is considered a “manual” triggering of\nthe popover.</p>\n",
"description": "<p>Toggles an element’s popover. This is considered a “manual” triggering of\nthe popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>\nonly hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3</p>\n",
"args": [
{
"name": "value",
Expand Down
3 changes: 2 additions & 1 deletion src/dropdown/bs-dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export class BsDropdownDirective implements OnInit, OnDestroy {

/**
* Toggles an element’s popover. This is considered a “manual” triggering of
* the popover.
* the popover. With parameter <code>true</code> allows toggling, with parameter <code>false</code>
* only hides opened dropdown. Parameter usage will be removed in ngx-bootstrap v3
*/
toggle(value?: boolean): void {
if (this.isOpen || !value) {
Expand Down