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

Nonpassive event modifier #5287

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/compile/nodes/Element.ts
Expand Up @@ -80,7 +80,8 @@ const valid_modifiers = new Set([
'capture',
'once',
'passive',
'self'
'nonpassive',
'self',
]);

const passive_events = new Set([
Expand Down
24 changes: 18 additions & 6 deletions src/compiler/compile/render_dom/wrappers/Element/EventHandler.ts
Expand Up @@ -45,12 +45,24 @@ export default class EventHandlerWrapper {

const args = [];

const opts = ['passive', 'once', 'capture'].filter(mod => this.node.modifiers.has(mod));
if (opts.length) {
args.push((opts.length === 1 && opts[0] === 'capture')
? TRUE
: x`{ ${opts.map(opt => p`${opt}: true`)} }`);
} else if (block.renderer.options.dev) {
const opts = ['nonpassive', 'passive', 'once', 'capture'].filter(mod => this.node.modifiers.has(mod));
if (opts.length) {
let opts_as_string;

if (opts[0] === 'nonpassive') {
opts.shift();

if (!opts.includes('passive')) {
opts.push('passive');
}
opts_as_string = opts.map(opt => p`${opt}: ${opt === 'passive' ? false : true}`);
Copy link
Member

Choose a reason for hiding this comment

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

should add validation to prevent passive and nonpassive to be used together

}
else {
opts_as_string = opts.map(opt => p`${opt}: true`);
}
args.push((opts.length === 1 && opts[0] === 'capture') ? TRUE : x`{ ${opts_as_string} }`);
}
else if (block.renderer.options.dev) {
args.push(FALSE);
}

Expand Down
2 changes: 1 addition & 1 deletion test/validator/samples/event-modifiers-invalid/errors.json
@@ -1,5 +1,5 @@
[{
"message": "Valid event modifiers are preventDefault, stopPropagation, capture, once, passive or self",
"message": "Valid event modifiers are preventDefault, stopPropagation, capture, once, passive, nonpassive or self",
"code": "invalid-event-modifier",
"start": {
"line": 1,
Expand Down