Do not announce 0 added/removed with screenreader

In unified diff, for added and removed lines there is one empty line
number column which should not be announced. We might want to
further refine this, but for now this is the least controversial change
that will stop the confusing, extraneous "0 added/removed"
announcements.

Bug: Issue 8068
Change-Id: I1c5f7eb8927ef75d868116154cccbc830d152e03
This commit is contained in:
Ole Rehmsen 2019-12-16 22:47:49 +01:00
parent 08b7525bbd
commit cb70ca6e5f

View File

@ -307,10 +307,16 @@
td.classList.add(opt_class);
}
if (line.type === GrDiffLine.Type.REMOVE) {
td.setAttribute('aria-label', `${number} removed`);
} else if (line.type === GrDiffLine.Type.ADD) {
td.setAttribute('aria-label', `${number} added`);
// Add aria-labels for valid line numbers.
// For unified diff, this method will be called with number set to 0 for
// the empty line number column for added/removed lines. This should not
// be announced to the screenreader.
if (number > 0) {
if (line.type === GrDiffLine.Type.REMOVE) {
td.setAttribute('aria-label', `${number} removed`);
} else if (line.type === GrDiffLine.Type.ADD) {
td.setAttribute('aria-label', `${number} added`);
}
}
if (line.type === GrDiffLine.Type.BLANK) {