Skip to content

Commit

Permalink
fix(table): do not prevent space input on textarea (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil147 authored and GitHub Enterprise committed Oct 18, 2021
1 parent f2fb505 commit 66b0c9c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 35 additions & 1 deletion projects/ng-aquila/src/table/table-row.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe(NxTableRowComponent.name, () => {
});
});

['a', 'button', 'input', 'label'].forEach((type) => {
['a', 'button', 'input', 'label', 'textarea'].forEach((type) => {
describe(`when clicking a "${type}" in the row`, () => {
beforeEach(() => {
tableRowElement.nativeElement.querySelector(type).click();
Expand All @@ -135,6 +135,37 @@ describe(NxTableRowComponent.name, () => {
});
});

['input', 'textarea'].forEach((type) => {
describe(`when typing inside "${type}"`, () => {
[true, false].forEach(selectable => {
describe(`for selectable being ${selectable}`, () => {
beforeEach(() => {
(testInstance as SelectableTableRowComponent).selectable = selectable;
fixture.detectChanges();
const element = tableRowElement.nativeElement.querySelector(type);
element.dispatchEvent(new KeyboardEvent('keydown', {cancelable: true, bubbles: true, key: 'Space'}));
fixture.detectChanges();
});

it('should not block space inputs', () => {
const element = tableRowElement.nativeElement.querySelector(type);
const event = new KeyboardEvent('keydown', {cancelable: true, bubbles: true, key: 'Space', keyCode: 32});
element.dispatchEvent(event);
fixture.detectChanges();

expect(event.defaultPrevented).toBe(false);

});

it ('is not selected', () => {
expect(tableRowInstance.selected).toBeFalsy();
expect(hasClass(tableRowElement, 'is-selected')).toBeFalsy();
});
});
});
});
});

describe('when selecting a row by pressing space', () => {
beforeEach(() => {
tableRowElement.nativeElement.dispatchEvent(new KeyboardEvent('keydown', {bubbles: true, key: 'Space'}));
Expand Down Expand Up @@ -195,6 +226,9 @@ class BasicTableRowComponent extends TableRowTest { }
<td>
<button>example button</button>
</td>
<td>
<textarea></textarea>
</td>
</tr>
`,
changeDetection: ChangeDetectionStrategy.OnPush
Expand Down
2 changes: 1 addition & 1 deletion projects/ng-aquila/src/table/table-row.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class NxTableRowComponent {
let parent: HTMLElement = $event.target as HTMLElement;

while (parent && parent !== this._elementRef.nativeElement) {
if (['A', 'INPUT', 'BUTTON'].indexOf(parent.tagName) >= 0) {
if (['A', 'INPUT', 'BUTTON', 'TEXTAREA'].indexOf(parent.tagName) >= 0) {
return true;
} else if (parent.tagName === 'LABEL' && parent.getAttribute('for')) {
return true;
Expand Down

0 comments on commit 66b0c9c

Please sign in to comment.