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

Ensure correct this context for addMembership function to call the blur method correctly. Fixes #10555 #10560

Merged
Merged
Changes from 1 commit
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
8 changes: 5 additions & 3 deletions modules/ui/sections/raw_membership_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ export function uiSectionRawMembershipEditor(context) {
}


function addMembership(d, role) {
this.blur(); // avoid keeping focus on the button
function addMembership(d, role, domElement) {
if (domElement && typeof domElement.blur === 'function') {
domElement.blur(); // avoid keeping focus on the button
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a defensive fix, but since addMembership is only called from one place, I think it would be cleaner to move this blur call to the caller, or even replace this with a closure that blurs the element, which would explicitly be in scope:

.on('accept', acceptEntity)

As it is, if acceptEntity has to bail for some reason, it won’t blur the element, which might result in the menu getting stuck on screen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion @1ec5 ! I completely agree that handling the blur() in a closure at the .on('accept') level would ensure the element is blurred reliably and keeps the UI logic separate from addMembership. I will updat the code to use the closure approach, which explicitly handles the blurring before calling acceptEntity.

_showBlank = false;

function actionAddMembers(relationId, ids, role) {
Expand Down Expand Up @@ -557,7 +559,7 @@ export function uiSectionRawMembershipEditor(context) {
if (d.relation) utilHighlightEntities([d.relation.id], false, context);

var role = context.cleanRelationRole(list.selectAll('.member-row-new .member-role').property('value'));
addMembership(d, role);
addMembership(d, role, this);
}


Expand Down