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

Display a custom ABBR title which also works on mobiles #265

Merged
merged 1 commit into from
Jan 14, 2024

Conversation

spaze
Copy link
Owner

@spaze spaze commented Jan 14, 2024

On mobiles, there's no way to display the ABBR title attribute. So let's create one way.

Heavily inspired by this https://bitsofco.de/making-abbr-work-for-touchscreen-keyboard-mouse/ and a bit by this https://stackoverflow.com/a/69353021/10537872

The relevant changes are that the title is read from the data-title attribute, which is created on mouseover from the regular title attribute which is then removed and added back on mouseout. Trying to keep the original attribute there for screen readers etc.

On mouseout, the blur() method is also called which "cancels" the focus state, in which the element is when it was clicked on. Without this, if you clicked the ABBR tag on desktop, the title would be visible until you've clicked again somewhere.

JS is also used to add tabindex=0 because the attribute tag is created by Texy and it would require some more work to add it to HTML. The attribute makes the element reachable by using a keyboard.

On mobiles, there's no way to display the ABBR title attribute. So let's create one way.

Heavily inspired by this https://bitsofco.de/making-abbr-work-for-touchscreen-keyboard-mouse/ and a bit by this https://stackoverflow.com/a/69353021/10537872

The relevant changes are that the title is read from the `data-title` attribute, which is created on mouseover from the regular `title` attribute which is then removed and added back on mouseout. Trying to keep the original attribute there for screen readers etc.

On mouseout, the `blur()` method is also called which "cancels" the focus state, in which the element is when it was clicked on. Without this, if you clicked the ABBR tag on desktop, the title would be visible until you've clicked again somewhere.

JS is also used to add `tabindex=0` because the attribute tag is created by Texy and it would require some more work to add it to HTML. The attribute makes the element reachable by using a keyboard.
@spaze spaze self-assigned this Jan 14, 2024
@spaze spaze merged commit 9976c7f into main Jan 14, 2024
32 checks passed
@spaze spaze deleted the spaze/abbr-mobile branch January 14, 2024 03:15
spaze added a commit that referenced this pull request Nov 17, 2024
Because Safari 15.8 doesn't support it and while newer ones do, this is easy to change.

Introduced in #265
spaze added a commit that referenced this pull request Nov 17, 2024
Because Safari 15.8 doesn't support it and while newer ones do, this is easy to change.

Introduced in #265
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