File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export default class ExtendedTimeElement extends HTMLElement {
2323
2424 // Internal: Refresh the time element's formatted date when an attribute changes.
2525 attributeChangedCallback ( attrName : string , oldValue : string , newValue : string ) {
26+ const oldTitle = this . getFormattedTitle ( )
2627 if ( attrName === 'datetime' ) {
2728 const millis = Date . parse ( newValue )
2829 if ( isNaN ( millis ) ) {
@@ -31,8 +32,10 @@ export default class ExtendedTimeElement extends HTMLElement {
3132 datetimes . set ( this , new Date ( millis ) )
3233 }
3334 }
35+
3436 const title = this . getFormattedTitle ( )
35- if ( title && ! this . hasAttribute ( 'title' ) ) {
37+ const currentTitle = this . getAttribute ( 'title' )
38+ if ( title && ( ! currentTitle || currentTitle === oldTitle ) ) {
3639 this . setAttribute ( 'title' , title )
3740 }
3841
Original file line number Diff line number Diff line change @@ -28,6 +28,17 @@ suite('title-format', function() {
2828 assert . match ( time . getAttribute ( 'title' ) , / \d { 4 } / )
2929 } )
3030
31+ test ( 'update the title attribute after a datetime value change' , function ( ) {
32+ const time = document . createElement ( 'local-time' )
33+ time . setAttribute ( 'datetime' , '1970-05-01T00:00:00.000Z' )
34+ assert . match ( time . getAttribute ( 'title' ) , / 1 9 7 0 / )
35+ time . setAttribute ( 'datetime' , '1979-05-01T00:00:00.000Z' )
36+ assert . match ( time . getAttribute ( 'title' ) , / 1 9 7 9 / )
37+ time . setAttribute ( 'title' , 'custom title' )
38+ time . setAttribute ( 'datetime' , '1989-05-01T00:00:00.000Z' )
39+ assert . match ( time . getAttribute ( 'title' ) , / c u s t o m t i t l e / )
40+ } )
41+
3142 test ( 'set the title attribute when parsed element is upgraded' , function ( ) {
3243 const root = document . createElement ( 'div' )
3344 root . innerHTML = '<local-time datetime="1970-01-01T00:00:00.000Z"></local-time>'
You can’t perform that action at this time.
0 commit comments