-
Notifications
You must be signed in to change notification settings - Fork 357
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
feat(data-table): onclick event for datatable rows, select event only on checkboxes, multi shift click and basic a11y (closes #468) (closes #592) #572
Conversation
Is it possible to add another option? I'd like to have a selectable row w/ the checkbox, but only if you click the checkbox element and not the entire row. This is for when you have other clickable buttons and elements in columns in the row. |
hi @jeremysmartt is it ready to test? |
The code is not released yet. Once is merged you, can install it from the
edit: wont be in the nightly build until its merged. |
@hengkyz Please feel free to test it out in our nightly build and give feedback on whether it is what you are expecting or not. |
ok @jeremysmartt i will check on it, |
i did install from nightly build but i did not see the code you change in there, |
Nightly is built off master. This hasn't been merged yet |
@kyleledbetter ok thank you |
…the checkbox element and not the entire row
any chance we can sneak in some keyboard support for tabbing through rows, selecting one/multiple, etc? :) (MVP of course) |
Unit tests are failing Also needs unit tests for the shift click enhancement |
…st that simulate the shift click behavior and tests that is works
unit test added |
Dont know if the a11y of the shift click is correct, it starts behaving weird when i keep clicking around while holding shift.. while i would expect that the first place i clicked to be the reference as long as i keep holding it. e.g. Although since it this case for the data table is |
*/ | ||
@HostListener('window:mouseup', ['$event']) | ||
reEnableOnSelectStart(): void { | ||
if (event.srcElement.tagName === 'MD-PSEUDO-CHECKBOX') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using window
and check for document
since it might affect server side rendering later on.
Also i think its better to bind the event to the md-pseudo-checkbox
and be sure it comes from it, instead of comparing the tagName
e.g.
/**
* Overrides the onselectstart method of the document so other text on the page
* doesn't get selected when doing shift selections.
*/
disableOnSelectStart(): void {
if (document) {
document.onselectstart = function(): boolean {
return false;
};
}
}
/**
* Resets the original onselectstart method.
*/
enableOnSelectStart(): void {
if (document) {
document.onselectstart = undefined;
}
}
<md-pseudo-checkbox
[state]="isRowSelected(row) ? 'checked' : 'unchecked'"
(mouseup)="enableOnSelectStart()"
(mousedown)="disableOnSelectStart()"
(click)="select(row, !isRowSelected(row), $event)">
</md-pseudo-checkbox>
Which we can probably create a directive later on for this if we want to reuse the functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is better to import document
from the constructor as optional and then use it
@Optional() @Inject(DOCUMENT) private _document: any
@@ -255,8 +256,70 @@ describe('Component: DataTable', () => { | |||
})(); | |||
}); | |||
|
|||
}); | |||
it('should shift click and select a range of rows', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍷
also point the text selection events directly into the md-pseudo-checkbox instead of the host component and comparing the tagName
added space press to select all checkbox also added support for enter/space/up/down on data table rows
Added some commits for basic keyboard |
before it was finding the selected rows, but as a user i would expect to always toggle from first index to last index also its better to simplify it for performance issues, since with lots of rows this couldve take a toll
Also simplified the code for shift selection
|
wow good news all check have passed, |
…doing shift click. Also fixing case where selecting a row and then unselecting everything
…th arrow keys only, no mouse
…f set to false the event isn't fired.
@hengkyz yep, we are doing the last polish steps since its more than just the clickRow event. Once we merge it, we will release |
…for being able to deselect current selection when multiple is false
we need to check the prev state when its single selection
…radata/covalent into feature/datatable-row-onclick
i've tried this but got some bug |
hi @emoralesb05 @jeremysmartt any idea about my report above? |
Bug reports should be created as a separate issue, almost nobody looks at merged PR's. 😄 Please open an issue with the bug or behavior you were expecting and be as detailed as possible. |
ok sorry don't know about that |
Description
feat(data-table):
(rowClick)
event for datatable rows enabled by new[clickable]
input.feat(data-table): select event will be trigger only when clicking on checkbox.
feat(data-table): shift-click for multiple row selection/deselection
feat(data-table): improved keyboard
a11y
for row selection (space, enter, up, down)What's included?
Test Steps
General Tests for Every PR
ng serve --aot
still works.npm run lint
passes.npm test
passes and code coverage is not lower.npm run build
still works.