Skip to content

[USWDS] COMBOBOX | Fix textContent combobox#4287

Merged
thisisdano merged 5 commits into
developfrom
gsq-fix-textcontent-combobox
Aug 17, 2021
Merged

[USWDS] COMBOBOX | Fix textContent combobox#4287
thisisdano merged 5 commits into
developfrom
gsq-fix-textcontent-combobox

Conversation

@scottqueen-bixal

Copy link
Copy Markdown
Contributor

Manually creates li and includes option.text as the safer li.textContent

includes a new test to check for potentially rendered innerHtml of list child elements.

Before you hit Submit, make sure you’ve done whichever of these applies to you:

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

@mejiaj mejiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, seems to resolve the text issue.

@scottqueen-bixal scottqueen-bixal marked this pull request as ready for review August 12, 2021 18:10

@thisisdano thisisdano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This look good to me. Thanks!
@aduth any comments?

@aduth

aduth commented Aug 12, 2021

Copy link
Copy Markdown
Contributor

Looks good to me 👍

Comment thread spec/unit/combo-box/combo-box.spec.js Outdated
Comment on lines +510 to +517
// eslint-disable-next-line no-plusplus
for (let i = 0; i < list.children.length; i++) {
assert.strictEqual(
list.children[i].children.innerHTML,
undefined,
"should not contain child HTML"
);
}

@aduth aduth Aug 12, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

children.innerHTML will always be undefined, because children is the array-like collection. You may need a nested loop to check each list item's children. As an alternative to checking innerHTML, you could check that each child is a text node.

Suggested change
// eslint-disable-next-line no-plusplus
for (let i = 0; i < list.children.length; i++) {
assert.strictEqual(
list.children[i].children.innerHTML,
undefined,
"should not contain child HTML"
);
}
Array.from(list.children).forEach((listItem) => {
Array.from(listItem.children).forEach((childNode) => {
assert.strictEqual(childNode, Node.TEXT_NODE);
});
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TIL!! this change worked for us locally - committing the suggestion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hm, something's not quite right with this actually. That assertion should be checking childNode.nodeType. In debugging, it looks like the assertion's not being called, because Array.from(listItem.children) is empty, even though that's valid in the real-world 🤷 Might need to revert back to plain-ol' for loop?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oof, this thing is trickier than I expected, taking another gander

@aduth aduth Aug 12, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I see the issue. children doesn't include the text nodes (source). Works after switching to childNodes.

    Array.from(list.children).forEach((listItem) => {
      Array.from(listItem.childNodes).forEach((childNode) => {
        assert.strictEqual(childNode.nodeType, Node.TEXT_NODE);
      });
    });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

confirming that nodeType is returning 3

Screen Shot 2021-08-12 at 5 05 08 PM

@thisisdano thisisdano merged commit 5358856 into develop Aug 17, 2021
@thisisdano thisisdano deleted the gsq-fix-textcontent-combobox branch August 17, 2021 21:45
@thisisdano thisisdano mentioned this pull request Aug 18, 2021
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.

4 participants