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

Create <map-caption> custom element #741

Merged
merged 15 commits into from
Feb 15, 2023
Merged

Conversation

kevinkim31
Copy link
Contributor

Closes #736

@kevinkim31 kevinkim31 self-assigned this Feb 3, 2023
@prushforth
Copy link
Member

I think that the generated aria-label should be removed if the <map-caption> is disconnected / deleted? WDYT?

@kevinkim31 kevinkim31 marked this pull request as ready for review February 7, 2023 14:08
@AliyanH

This comment was marked as resolved.

@AliyanH
Copy link
Member

AliyanH commented Feb 7, 2023

This is working great, just had 2 comments:

  • I think we should probably have a test for testing the removal of map-caption now that it is functioning properly.
  • When you have multiple <map-caption>'s I think the most recently added map-caption is used, which seems logical, but once that most recent map-caption is removed and there are other map-captions that are present, the mapml-viewer does not incorporate them, which does not seem right. I would assume it should used the second most recent one?

implement <map-caption> custom element for web-map

fix minor details and addded comment about potential features and limitations

add tests

fix minor details for testing

Revert "Merge branch 'map-caption' of https://github.com/kevinkim31/Web-Map-Custom-Element into map-caption"

This reverts commit 770e2a7, reversing
changes made to b9b8ddb.

add tests

fix minor details for testing

add removing function

add removing function
@kevinkim31
Copy link
Contributor Author

kevinkim31 commented Feb 7, 2023

  • When you have multiple <map-caption>'s I think the most recently added map-caption is used, which seems logical, but
    once that most recent map-caption is removed and there are other map-captions that are present, the mapml-viewer does not incorporate them, which does not seem right. I would assume it should used the second most recent one?

I think this would require adding code to mapml-viewer itself, which I'm not sure is an issue or not.

Copy link
Member

@AliyanH AliyanH left a comment

Choose a reason for hiding this comment

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

some comments

src/map-caption.js Outdated Show resolved Hide resolved
src/map-caption.js Outdated Show resolved Hide resolved
src/mapml-viewer.js Show resolved Hide resolved
@kevinkim31
Copy link
Contributor Author

kevinkim31 commented Feb 10, 2023

Fixes:

  • Only allows innerHTML modifications to the first map-caption
  • Doesn't delete aria-label when one was initially set up by user; even if separate map-caption elements are created
  • Only the first map-captioncan modify and remove the aria-label except for if aria-label is created manually (mentioned in previous point)

Copy link
Member

@prushforth prushforth left a comment

Choose a reason for hiding this comment

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

Tests look good, I suggest a few updates, if possible. Thanks!

connectedCallback() {

// calls MutationObserver; needed to observe changes to content between <map-caption> tags and update to aria-label
let mapcaption = this.parentElement.querySelector('map-caption').innerHTML;
Copy link
Member

Choose a reason for hiding this comment

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

I think you can use this.textContent here, unless I'm mistaken. Also, the query you're making is returning the first and only the first of potentially many <map-caption> elements, which will sometimes be this one, and sometimes not.

I think .textContent is appropriate here. I could be convinced otherwise, but See for a discussion: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#differences_from_innertext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For mapcaption, I need this to return the first map-caption only so that I can store it to then compare it to the mapcaption that was removed/modified.

src/map-caption.js Outdated Show resolved Hide resolved
src/map-caption.js Outdated Show resolved Hide resolved
// don't change aria-label if one already exists from user (checks when element is first created)
if (!this.parentElement.hasAttribute('aria-label'))
{
const ariaLabel = this.textContent;
Copy link
Member

Choose a reason for hiding this comment

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

Good use of textContent, see comment above

src/map-caption.js Outdated Show resolved Hide resolved
}
});

this.observer.observe(this, {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe observing too much, perhaps only subtree is necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Still think that we're observing too much for <map-caption>, only need to watch our content / subtree, no? If you disagree, put a comment below, then mark as resolved. Thanks.

src/web-map.js Outdated
let mapcaption = this.querySelector('map-caption');

if (mapcaption != null){
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Why is it required to put this on the event queue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so that the ariaupdate has time to load

src/web-map.js Outdated Show resolved Hide resolved
src/web-map.js Outdated Show resolved Hide resolved
src/web-map.js Outdated Show resolved Hide resolved
Copy link
Member

@prushforth prushforth left a comment

Choose a reason for hiding this comment

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

A couple of small things. A test for when you add <map-caption> inside e.g. <layer-> to show it doesn't add aria-label to that element would be good.

src/map-caption.js Show resolved Hide resolved
}
});

this.observer.observe(this, {
Copy link
Member

Choose a reason for hiding this comment

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

Still think that we're observing too much for <map-caption>, only need to watch our content / subtree, no? If you disagree, put a comment below, then mark as resolved. Thanks.

src/map-caption.js Outdated Show resolved Hide resolved
src/web-map.js Outdated Show resolved Hide resolved
Copy link
Member

@prushforth prushforth left a comment

Choose a reason for hiding this comment

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

LGTM

@prushforth prushforth merged commit abff1aa into Maps4HTML:main Feb 15, 2023
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.

Web map title or caption
3 participants