Skip to content

Commit

Permalink
MDL-78885 comboboxsearch: Switch event listener from 'click' to 'change'
Browse files Browse the repository at this point in the history
Move from listening to 'click' to listening to 'change'
  • Loading branch information
rezaies committed Mar 21, 2024
1 parent bff7c88 commit 8e2555d
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 68 deletions.
2 changes: 1 addition & 1 deletion grade/amd/build/comboboxsearch/grade.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion grade/amd/build/comboboxsearch/grade.min.js.map

Large diffs are not rendered by default.

27 changes: 22 additions & 5 deletions grade/amd/src/comboboxsearch/grade.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export default class GradeItemSearch extends search_combobox {
const component = document.querySelector(this.componentSelector());
this.courseID = component.querySelector(this.selectors.courseid).dataset.courseid;

const searchValueElement = this.component.querySelector(`#${this.searchInput.dataset.inputElement}`);
searchValueElement.addEventListener('change', () => {
this.toggleDropdown(); // Otherwise the dropdown stays open when user choose an option using keyboard.

const valueElement = this.component.querySelector(`#${this.combobox.dataset.inputElement}`);
if (valueElement.value !== searchValueElement.value) {
valueElement.value = searchValueElement.value;
valueElement.dispatchEvent(new Event('change', {bubbles: true}));
}

searchValueElement.value = '';
});

this.renderDefault();
}

Expand Down Expand Up @@ -139,7 +152,6 @@ export default class GradeItemSearch extends search_combobox {
return {
id: grade.id,
name: grade.name,
link: this.selectOneLink(grade.id),
};
})
);
Expand Down Expand Up @@ -181,10 +193,15 @@ export default class GradeItemSearch extends search_combobox {
// Display results.
await this.filterrenderpipe();
}
// Prevent normal key presses activating this.
if (e.target.closest('.dropdown-item') && e.button === 0) {
window.location = e.target.closest('.dropdown-item').href;
}
}

/**
* The handler for when a user changes the value of the component (selects an option from the dropdown).
*
* @param {Event} e The change event.
*/
changeHandler(e) {
window.location = this.selectOneLink(e.target.value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Feature: Within the grader report, test that we can search for users
And the field "perpage" matches value "20"
When I set the field "Search users" to "42"
# One of the users' phone numbers also matches.
And I wait until "View all results (2)" "link" exists
And I wait until "View all results (2)" "option_role" exists
Then I confirm "Student s42" in "user" search within the gradebook widget exists

Scenario: As a teacher I save grades using search and pagination
Expand All @@ -364,7 +364,7 @@ Feature: Within the grader report, test that we can search for users
And I wait until the page is ready
# Search for a single user on second page and save grades.
When I set the field "Search users" to "test32"
And I wait until "View all results (1)" "link" exists
And I wait until "View all results (1)" "option_role" exists
And I click on "Student test32" "option_role"
And I wait until the page is ready
And I give the grade "80.00" to the user "Student test32" for the grade item "Test assignment one"
Expand Down Expand Up @@ -409,7 +409,7 @@ Feature: Within the grader report, test that we can search for users
| Student test32 |
# Search for multiple users on second page and save grades.
And I set the field "Search users" to "test3"
And I wait until "View all results (11)" "link" exists
And I wait until "View all results (11)" "option_role" exists
And I click on "View all results (11)" "option_role"
And I wait until the page is ready
And I give the grade "10.00" to the user "Student test32" for the grade item "Test assignment one"
Expand Down
2 changes: 1 addition & 1 deletion group/amd/build/comboboxsearch/group.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8e2555d

Please sign in to comment.