MOBILE-3744 icon: Detect and notify empty aria labels

main
Pau Ferrer Ocaña 2021-04-27 12:09:12 +02:00
parent 1abd630ffa
commit 0d935e672e
2 changed files with 19 additions and 2 deletions

View File

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, Input, OnChanges, ElementRef, SimpleChange } from '@angular/core'; import { Component, Input, OnChanges, ElementRef, SimpleChange } from '@angular/core';
import { CoreLogger } from '@singletons/logger';
/** /**
* Core Icon is a component that enables the posibility to add fontawesome icon to the html. It * Core Icon is a component that enables the posibility to add fontawesome icon to the html. It
@ -47,6 +48,8 @@ export class CoreIconComponent implements OnChanges {
el: ElementRef, el: ElementRef,
) { ) {
this.element = el.nativeElement; this.element = el.nativeElement;
CoreLogger.getInstance('CoreIconComponent').error('CoreIconComponent is deprecated. Please use ion-icon instead.');
} }
/** /**

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Directive, ElementRef, Input, OnChanges, SimpleChange } from '@angular/core'; import { AfterViewInit, Directive, ElementRef, Input, OnChanges, SimpleChange } from '@angular/core';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { Http } from '@singletons'; import { Http } from '@singletons';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
@ -28,7 +28,7 @@ import { CoreConstants } from '@/core/constants';
@Directive({ @Directive({
selector: 'ion-icon[name]', selector: 'ion-icon[name]',
}) })
export class CoreFaIconDirective implements OnChanges { export class CoreFaIconDirective implements AfterViewInit, OnChanges {
@Input() name = ''; @Input() name = '';
@ -82,11 +82,25 @@ export class CoreFaIconDirective implements OnChanges {
} }
} else { } else {
this.element.removeAttribute('src'); this.element.removeAttribute('src');
this.logger.warn(`Ionic icon ${this.name} detected`);
} }
return; return;
} }
/**
* @inheritdoc
*/
ngAfterViewInit(): void {
if (!this.element.getAttribute('aria-label') &&
!this.element.getAttribute('aria-labelledby') &&
this.element.getAttribute('aria-hidden') != 'true') {
this.logger.warn('Aria label not set on icon ' + this.name, this.element);
this.element.setAttribute('aria-hidden', 'true');
}
}
/** /**
* Detect changes on input properties. * Detect changes on input properties.
*/ */