-
Notifications
You must be signed in to change notification settings - Fork 22.9k
SVG event handlers: optional edit #41602
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
base: main
Are you sure you want to change the base?
Conversation
Preview URLs Flaws (14)URL:
(comment last updated: 2025-10-20 11:47:04) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estelle sure, makes sense. One suggestion for you to look at.
Co-authored-by: Chris Mills <chrisdavidmills@gmail.com>
Sooo, I took the same approach as #41264. I took the union of event handlers documented before and after this PR, and also all Code<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<style>
body {
width: 1400px;
display: flex;
flex-wrap: wrap;
}
div {
width: 150px;
border: 2px solid black;
text-align: center;
margin: 0.2em;
padding: 0.2em;
}
[data-svg-fired]:not([data-text-fired]) {
background: lightcoral;
}
[data-text-fired]:not([data-svg-fired]) {
background: lightyellow;
}
[data-svg-fired][data-text-fired] {
background: lightgreen;
}
</style>
</head>
<body>
<script>
const attrs = `onabort
onactivate
onauxclick
onbeforeinput
onbeforematch
onbeforetoggle
onbegin
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncommand
oncontextlost
oncontextmenu
oncontextrestored
oncopy
oncuechange
oncut
ondblclick
ondrag
ondragend
ondragenter
ondragleave
ondragover
ondragstart
ondrop
ondurationchange
onemptied
onend
onended
onerror
onfocus
onfocusin
onfocusout
onformdata
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadstart
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onmousewheel
onpaste
onpause
onplay
onplaying
onprogress
onratechange
onrepeat
onreset
onresize
onscroll
onscrollend
onsecuritypolicyviolation
onseeked
onseeking
onselect
onshow
onslotchange
onstalled
onsubmit
onsuspend
ontimeupdate
ontoggle
onunload
onvolumechange
onwaiting
onwheel`.split("\n");
function testEvent(type) {
const div = document.createElement("div");
div.id = `event-${type}`;
div.textContent = type;
document.body.appendChild(div);
const svg = document.createElementNS(
"http://www.w3.org/2000/svg",
"svg",
);
svg.setAttribute(
`on${type}`,
`document.getElementById('event-${type}').setAttribute('data-svg-fired', 'yes')`,
);
svg.dispatchEvent(new Event(type));
const text = document.createElementNS(
"http://www.w3.org/2000/svg",
"tspan",
);
text.setAttribute(
`on${type}`,
`document.getElementById('event-${type}').setAttribute('data-text-fired', 'yes')`,
);
text.dispatchEvent(new Event(type));
}
const set1 = new Set(
[
...Object.getOwnPropertyNames(SVGElement.prototype),
...Object.getOwnPropertyNames(HTMLElement.prototype),
...Object.getOwnPropertyNames(Element.prototype),
]
.filter((p) => p.startsWith("on"))
.sort(),
);
const set2 = new Set(attrs);
const unconfirmed = set2.difference(set1);
console.log(unconfirmed);
for (const type of [...set1, ...unconfirmed]) {
testEvent(type.slice(2));
}
const supported = new Set([...document.querySelectorAll("[data-svg-fired], [data-text-fired]")].map((div) => `on${div.innerText}`));
const undocumented = supported.difference(set2);
const documentedUnsupported = set2.difference(supported);
for (const type of undocumented) {
document.getElementById(`event-${type.slice(2)}`).style.border = "2px solid red";
}
for (const type of documentedUnsupported) {
document.getElementById(`event-${type.slice(2)}`).style.border = "2px dashed blue";
}
</script>
</body>
</html> In this diagram, green background means "supported"; yellow means "supported on ![]() So, it appears that we have the following anomalies:
This is tested in Chrome only. It woudl take significantly more effort to do cross-browser testing but this is a good starting point. |
This was originally part of #41583, but as another option is just to remove the entire section, i pulled this into a different PR. We can add something like this, or, optionally, get rid of the list altogether.