[Angular CDK] Better control over the outside click event #213
Replies: 4 comments 23 replies
-
@pawel-twardziak is there an example of similar logic implementation in other libraries? |
Beta Was this translation helpful? Give feedback.
-
I don't see any other UI lib that counts taking care about what I am proposing. So we could come up to the developers with a simple primitives registry and its internal API partially exposed via IMHO that would be a game changer for creative developers. The more functional are out funabilities, the more fertile creativity of programmers 🚀 |
Beta Was this translation helpful? Give feedback.
-
Off-topic, but about popovers :) |
Beta Was this translation helpful? Give feedback.
-
Recommended Approach
interface RdxEvent<T extends Event> {
originalEvent: T;
preventedFor: { [primitiveType: string]: Set<string> };
preventFor(primitiveType?: string, id?: string): void;
} import { Directive, HostListener, EventEmitter, Output } from '@angular/core';
@Directive({
selector: '[rdxEventWrapper]',
host: {
'(click)': 'onClick($event)'
}
})
export class RdxEventWrapperDirective {
@Output() rdxClick = new EventEmitter<RdxEvent<MouseEvent>>();
onClick(event: MouseEvent) {
const rdxEvent: RdxEvent<MouseEvent> = {
originalEvent: event,
preventedFor: {},
preventFor: (primitiveType?: string, id?: string) => {
const type = primitiveType || 'global';
if (!rdxEvent.preventedFor[type]) {
rdxEvent.preventedFor[type] = new Set<string>();
}
rdxEvent.preventedFor[type].add(id || '__ALL__');
}
};
this.rdxClick.emit(rdxEvent);
}
} In shouldClose(event: RdxEvent<MouseEvent>): boolean {
const prevented = event.preventedFor['popover'];
if (prevented) {
if (prevented.has('__ALL__') || prevented.has(this.popoverId)) {
return false;
}
}
return true;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
in that PR https://github.com/radix-ng/primitives/pull/200/files I introduced this;
It has been removed in one of my next PRs as I found it an anti-pattern a bit
I don't think this can be considered an anti-pattern if it is released as an official feature and is included in the documentation.
What is the reason for having such keys on the events?
event.preventDefault()
. If we need more, Angular leaves it to our own implementation using CDK.event.preventDefault()
aims all the default listeners which is e.g.<a href="..." />
clickWhat feature could we implement to address the issues?
Steps:
MouseEvent
,KeyboardEvent
and any event that we are gonne use from the CDK@radix-ng/core @radix-ng/maintainers
share your thoughts about it please :)
Beta Was this translation helpful? Give feedback.
All reactions