Skip to content

Commit abc079e

Browse files
committed
Updates based on PR feedback to noTitle instead of hideTitle
1 parent fe78512 commit abc079e

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ So, a relative date phrase is used for up to a month and then the actual date is
8080
| `month` | `month` | `'numeric'\|'2-digit'\|'short'\|'long'\|'narrow'\|undefined` | <sup>***</sup> |
8181
| `year` | `year` | `'numeric'\|'2-digit'\|undefined` | <sup>****</sup> |
8282
| `timeZoneName` | `time-zone-name` | `'long'\|'short'\|'shortOffset'\|'longOffset'` `\|'shortGeneric'\|'longGeneric'\|undefined` | `undefined` |
83-
| `hideTitle` | `hide-title` | `boolean \| null` | - |
83+
| `noTitle` | `no-title` | `boolean \| null` | - |
8484

8585
<sup>*</sup>: If unspecified, `formatStyle` will return `'narrow'` if `format` is `'elapsed'` or `'micro'`, `'short'` if the format is `'relative'` or `'datetime'`, otherwise it will be `'long'`.
8686

@@ -269,9 +269,9 @@ For dates outside of the specified `threshold`, the formatting of the date can b
269269

270270
Lang is a [built-in global attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang). Relative Time will use this to provide an applicable language to the `Intl` APIs. If the individual element does not have a `lang` attribute then it will traverse upwards in the tree to find the closest element that does, or default the lang to `en`.
271271

272-
##### hideTitle (`boolean`, default: `undefined`)
272+
##### noTitle (`boolean`, default: `undefined`)
273273

274-
Passing in `hide-title="true"` will remove the `title` attribute from the `<relative-time>` element. The `title` attribute is inaccessible to screen reader and keyboard users, so hiding the title allows a user to create a custom accessible version of a tooltip if one is desired.
274+
Passing in `no-title="true"` will remove the `title` attribute from the `<relative-time>` element. The `title` attribute is inaccessible to screen reader and keyboard users, so no adding a title attribute allows a user to create a custom, accessible tooltip if one is desired.
275275

276276
## Browser Support
277277

examples/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ <h3>Format DateTime</h3>
2323

2424
<p>
2525
Hide title attribute:
26-
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit" hide-title="true">
26+
<relative-time datetime="1970-01-01T00:00:00.000Z" format="datetime" hour="numeric" minute="2-digit" second="2-digit"
27+
no-title="true">
2728
Jan 1 1970
2829
</relative-time>
2930
</p>
@@ -192,8 +193,8 @@ <h2>Localised Dates</h2>
192193
</relative-time>
193194
</p>
194195

195-
<!-- <script type="module" src="../dist/index.js"></script> -->
196-
<script type="module" src="https://unpkg.com/@github/relative-time-element@latest/dist/bundle.js"></script>
196+
<script type="module" src="../dist/index.js"></script>
197+
<!-- <script type="module" src="https://unpkg.com/@github/relative-time-element@latest/dist/bundle.js"></script> -->
197198
<script>
198199
document.body.addEventListener('relative-time-updated', event => {
199200
console.log('event from', event.target, event)

src/relative-time-element.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
107107
'precision',
108108
'format',
109109
'format-style',
110-
'hide-title',
110+
'no-title',
111111
'datetime',
112112
'lang',
113113
'title',
@@ -383,8 +383,8 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
383383
this.setAttribute('format-style', value)
384384
}
385385

386-
get hideTitle(): boolean {
387-
return this.getAttribute('hide-title') === 'true'
386+
get noTitle(): boolean {
387+
return this.hasAttribute('no-title') && this.getAttribute('no-title') === 'true'
388388
}
389389

390390
get datetime() {
@@ -436,7 +436,7 @@ export class RelativeTimeElement extends HTMLElement implements Intl.DateTimeFor
436436
return
437437
}
438438
const now = Date.now()
439-
if (!this.#customTitle && !this.hideTitle) {
439+
if (!this.#customTitle && !this.noTitle) {
440440
newTitle = this.#getFormattedTitle(date) || ''
441441
if (newTitle) this.setAttribute('title', newTitle)
442442
}

test/relative-time.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ suite('relative-time', function () {
8383
assert.equal(el.getAttribute('title'), text)
8484
})
8585

86-
test('does not set title if hide-title=true', async () => {
86+
test('does not set title if no-title=true', async () => {
8787
const el = document.createElement('relative-time')
8888
el.setAttribute('datetime', new Date().toISOString())
89-
el.setAttribute('hide-title', true)
89+
el.setAttribute('no-title', true)
9090
await Promise.resolve()
9191
assert.equal(el.getAttribute('title'), null)
9292
})
9393

94-
test('sets title if hide-title=false', async () => {
94+
test('sets title if no-title=false', async () => {
9595
const el = document.createElement('relative-time')
9696
el.setAttribute('datetime', new Date().toISOString())
97-
el.setAttribute('hide-title', false)
97+
el.setAttribute('no-title', false)
9898
await Promise.resolve()
9999
assert.ok(el.getAttribute('title'))
100100
})

0 commit comments

Comments
 (0)