Skip to content

fix(dds-datasets-point): stop assigning a duplicate id to every legend row - #1735

Open
zigzagdev wants to merge 1 commit into
googlemaps-samples:mainfrom
zigzagdev:fix/dds-datasets-point-legend-duplicate-ids
Open

zigzagdev wants to merge 1 commit into
googlemaps-samples:mainfrom
zigzagdev:fix/dds-datasets-point-legend-duplicate-ids

Conversation

@zigzagdev

Copy link
Copy Markdown

Summary

Motivation

makeLegend() in samples/dds-datasets-point/index.ts built the legend by looping once per fur color (9 colors) and setting wrapper.id = 'container' on every iteration, producing 9 sibling <div id="container"> elements. HTML ids must be unique per document, so document.getElementById('container') can only ever return the first of the 9 rows, and this breaks under any stricter HTML validator or linter even though it happened to render correctly today because the CSS used an ID selector (#legend #container) that browsers still match against every element.

The function also had a redundant no-op line. legend!.id = 'legend'; runs immediately after document.getElementById('legend'), reassigning the element's id to the exact id just used to look it up, which is leftover or copy-paste code with no effect.

What I have done

I replaced wrapper.id = 'container' with wrapper.classList.add('legend-row') in samples/dds-datasets-point/index.ts, so each legend row gets a class instead of a duplicate id.
Also I removed the no-op legend!.id = 'legend'; line, and updated samples/dds-datasets-point/style.css to target #legend .legend-row instead of #legend #container.

Test Plans

  • Ran npx tsc --noEmit -p samples/dds-datasets-point/tsconfig.json to confirm the sample still type checks.
  • Loaded the sample in a browser and visually confirmed the legend renders identically (title, 9 color rows, box plus label spacing) with no #legend #container CSS still applying.
  • Inspected the DOM to confirm each legend row now has class="legend-row" and no duplicate id="container" attributes remain.

Test Results

npx tsc --noEmit -p samples/dds-datasets-point/tsconfig.json passed with no errors.

…d row

makeLegend()'s loop set wrapper.id = 'container' on every iteration,
producing 9 sibling elements sharing the same id, which is invalid HTML
and makes document.getElementById('container') unreliable. Use a CSS
class instead. Also removed a no-op line that reassigned the legend
element's id to the id just used to look it up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant