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

HistoryTokenAnchorComponent.addXXXListener addEventListener #4432

Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -301,51 +301,52 @@ public HistoryTokenAnchorComponent addChangeListener(final ChangeListener<Option

@Override
public HistoryTokenAnchorComponent addClickListener(final EventListener listener) {
this.element.addEventListener(
EventType.click.getName(),
this.disabledAwareEventListener(listener)
return this.addEventListener(
EventType.click,
listener
);
return this;
}

@Override
public HistoryTokenAnchorComponent addFocusListener(final EventListener listener) {
this.element.addEventListener(
EventType.focus.getName(),
this.disabledAwareEventListener(listener)
return this.addEventListener(
EventType.focus,
listener
);
return this;
}

@Override
public HistoryTokenAnchorComponent addKeyupListener(final EventListener listener) {
this.element.addEventListener(
EventType.keydown.getName(),
this.disabledAwareEventListener(listener)
return this.addEventListener(
EventType.keyup,
listener
);
return this;
}

@Override
public HistoryTokenAnchorComponent addKeydownListener(final EventListener listener) {
this.element.addEventListener(
EventType.keydown.getName(),
this.disabledAwareEventListener(listener)
return this.addEventListener(
EventType.keydown,
listener
);
return this;
}

/**
* If this anchor is disabled calls {@link Event#preventDefault()} and skips calling the given {@link EventListener}.
*/
private EventListener disabledAwareEventListener(final EventListener listener) {
return (e) -> {
if (this.isDisabled()) {
e.preventDefault();
} else {
listener.handleEvent(e);
private HistoryTokenAnchorComponent addEventListener(final EventType eventType,
final EventListener listener) {
this.element.addEventListener(
eventType,
(e) -> {
if (this.isDisabled()) {
e.preventDefault();
} else {
listener.handleEvent(e);
}
}
};
);
return this;
}

/**
Expand Down
Loading