Skip to content

Commit

Permalink
[AAE-5362] Add option to make actions button visible only on hover (#…
Browse files Browse the repository at this point in the history
…7117)

* [AAE-5362] Add option to make actions button visible only on hover

* [AAE-5362] Refactor

* Unrelated linting fixes
  • Loading branch information
Thomas Hunter authored Jun 22, 2021
1 parent b5e4316 commit e2b8557
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/core/components/datatable.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ Learm more about styling your datatable: [Customizing the component's styles](#c
| ---- | ---- | ------------- | ----------- |
| actions | `boolean` | false | Toggles the data actions column. |
| actionsPosition | `string` | "right" | Position of the actions dropdown menu. Can be "left" or "right". |
| actionsVisibleOnHover | `boolean` | false | If set to true, the actions button will only be visible on row hover. |
| allowFiltering | `boolean` | false | Flag that indicate if the datatable allow the use facet [widget](../../../lib/testing/src/lib/core/pages/form/widgets/widget.ts) search for filtering. |
| columns | `any[]` | \[] | The columns that the datatable will show. |
| contextMenu | `boolean` | false | Toggles custom context menu for the component. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ describe('ContentMetadataComponent', () => {
component.displayEmpty = true;

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

let defaultProp = queryDom(fixture);
let exifProp = queryDom(fixture, 'EXIF');
Expand All @@ -419,7 +419,7 @@ describe('ContentMetadataComponent', () => {
component.displayAspect = 'CUSTOM';

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

defaultProp = queryDom(fixture);
exifProp = queryDom(fixture, 'EXIF');
Expand All @@ -431,7 +431,7 @@ describe('ContentMetadataComponent', () => {
component.displayAspect = 'Properties';

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

defaultProp = queryDom(fixture);
exifProp = queryDom(fixture, 'EXIF');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('DropdownSitesComponent', () => {
fixture.detectChanges();
await fixture.whenStable();

let options = debug.queryAll(By.css('mat-option'));
const options = debug.queryAll(By.css('mat-option'));
options[0].triggerEventHandler('click', null);

fixture.detectChanges();
Expand Down
6 changes: 3 additions & 3 deletions lib/core/comments/comments.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('CommentsComponent', () => {
getProcessCommentsSpy.and.returnValue(of([]));

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
Expand All @@ -145,7 +145,7 @@ describe('CommentsComponent', () => {
component.ngOnChanges({'taskId': change});

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
Expand All @@ -154,7 +154,7 @@ describe('CommentsComponent', () => {
component.readOnly = true;

fixture.detectChanges();
await fixture.whenStable()
await fixture.whenStable();

expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
[attr.data-automation-id]="'datatable-row-' + idx">
<!-- Actions (left) -->
<div *ngIf="actions && actionsPosition === 'left'" role="gridcell" class="adf-datatable-cell">
<button mat-icon-button [matMenuTriggerFor]="menu"
<button mat-icon-button [matMenuTriggerFor]="menu" #actionsMenuTrigger="matMenuTrigger"
[ngClass]="getHideActionsWithoutHoverClass(actionsMenuTrigger)"
[title]="'ADF-DATATABLE.CONTENT-ACTIONS.TOOLTIP' | translate"
[attr.id]="'action_menu_left_' + idx"
[attr.data-automation-id]="'action_menu_' + idx">
Expand Down Expand Up @@ -209,7 +210,8 @@
<div *ngIf="actions && actionsPosition === 'right'"
role="gridcell"
class="adf-datatable-cell adf-datatable__actions-cell adf-datatable-center-actions-column-ie">
<button mat-icon-button [matMenuTriggerFor]="menu"
<button mat-icon-button [matMenuTriggerFor]="menu" #actionsMenuTrigger="matMenuTrigger"
[ngClass]="getHideActionsWithoutHoverClass(actionsMenuTrigger)"
[attr.aria-label]="'ADF-DATATABLE.ACCESSIBILITY.ROW_OPTION_BUTTON' | translate"
[title]="'ADF-DATATABLE.CONTENT-ACTIONS.TOOLTIP' | translate"
[attr.id]="'action_menu_right_' + idx"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
top: 4px;
}

.adf-datatable-row:not(:hover) .adf-datatable-hide-actions-without-hover {
display: none;
}

.adf-image-table-cell {
margin: 8px;
padding: 4px;
Expand Down Expand Up @@ -439,6 +443,10 @@
display: flex;
}

.adf-datatable-row:not(:hover) .adf-datatable-hide-actions-without-hover {
display: none;
}

.adf-datatable-cell--image {
max-width: $data-table-thumbnail-width;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '@angular/core';
import { FocusKeyManager } from '@angular/cdk/a11y';
import { MatCheckboxChange } from '@angular/material/checkbox';
import { MatMenuTrigger } from '@angular/material/menu';
import { Subscription, Observable, Observer } from 'rxjs';
import { DataColumnListComponent } from '../../../data-column/data-column-list.component';
import { DataColumn } from '../../data/data-column.model';
Expand Down Expand Up @@ -103,6 +104,10 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
@Input()
actionsPosition: string = 'right'; // left|right

/** Toggles whether the actions dropdown should only be visible if the row is hovered over or the dropdown menu is open. */
@Input()
actionsVisibleOnHover: boolean = false;

/** Fallback image for rows where the thumbnail is missing. */
@Input()
fallbackThumbnail: string;
Expand Down Expand Up @@ -676,6 +681,10 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
}
}

getHideActionsWithoutHoverClass(actionsMenuTrigger: MatMenuTrigger) {
return { 'adf-datatable-hide-actions-without-hover': this.actionsVisibleOnHover && !actionsMenuTrigger.menuOpen };
}

rowAllowsDrop(row: DataRow): boolean {
return row.isDropTarget === true;
}
Expand Down

0 comments on commit e2b8557

Please sign in to comment.