Skip to content

Commit a86c8fd

Browse files
authored
Merge pull request #17151 from IgniteUI/rkaraivanov/remove-direction-service
removed: Direction service
2 parents 98a789a + e890746 commit a86c8fd

14 files changed

Lines changed: 56 additions & 241 deletions

File tree

projects/igniteui-angular/carousel/src/carousel/carousel.component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { NgClass, NgTemplateOutlet } from '@angular/common';
2-
import { AfterContentInit, Component, ContentChild, ContentChildren, ElementRef, EventEmitter, HostBinding, HostListener, Injectable, Input, IterableChangeRecord, IterableDiffer, IterableDiffers, OnDestroy, Output, QueryList, TemplateRef, ViewChild, ViewChildren, booleanAttribute, DOCUMENT, inject } from '@angular/core';
2+
import { AfterContentInit, Component, ContentChild, ContentChildren, ElementRef, EventEmitter, HostBinding, HostListener, Injectable, Input, IterableChangeRecord, IterableDiffer, IterableDiffers, OnDestroy, Output, QueryList, TemplateRef, ViewChild, ViewChildren, booleanAttribute, inject } from '@angular/core';
33
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
44
import { merge, Subject } from 'rxjs';
55
import { takeUntil } from 'rxjs/operators';
6-
import { CarouselResourceStringsEN, ICarouselResourceStrings, ɵIgxDirectionality } from 'igniteui-angular/core';
6+
import { CarouselResourceStringsEN, ICarouselResourceStrings, isLeftToRight} from 'igniteui-angular/core';
77
import { first, IBaseEventArgs, last, PlatformUtil } from 'igniteui-angular/core';
88
import { CarouselAnimationDirection, IgxCarouselComponentBase } from './carousel-base';
99
import { IgxCarouselIndicatorDirective, IgxCarouselNextButtonDirective, IgxCarouselPrevButtonDirective } from './carousel.directives';
@@ -64,8 +64,7 @@ export class IgxCarouselComponent extends IgxCarouselComponentBase implements On
6464
private element = inject(ElementRef);
6565
private iterableDiffers = inject(IterableDiffers);
6666
private platformUtil = inject(PlatformUtil);
67-
private dir = inject(ɵIgxDirectionality);
68-
private document = inject(DOCUMENT);
67+
6968

7069

7170
/**
@@ -725,21 +724,22 @@ export class IgxCarouselComponent extends IgxCarouselComponentBase implements On
725724
public handleKeydown(event: KeyboardEvent): void {
726725
const { key } = event;
727726
const slides = this.slides.toArray();
727+
const isRTL = !isLeftToRight(this.nativeElement);
728728

729729
switch (key) {
730730
case this.platformUtil.KEYMAP.ARROW_LEFT:
731-
this.dir.rtl ? this.next() : this.prev();
731+
isRTL ? this.next() : this.prev();
732732
break;
733733
case this.platformUtil.KEYMAP.ARROW_RIGHT:
734-
this.dir.rtl ? this.prev() : this.next();
734+
isRTL ? this.prev() : this.next();
735735
break;
736736
case this.platformUtil.KEYMAP.HOME:
737737
event.preventDefault();
738-
this.select(this.dir.rtl ? last(slides) : first(slides));
738+
this.select(isRTL ? last(slides) : first(slides));
739739
break;
740740
case this.platformUtil.KEYMAP.END:
741741
event.preventDefault();
742-
this.select(this.dir.rtl ? first(slides) : last(slides));
742+
this.select(isRTL ? first(slides) : last(slides));
743743
break;
744744
}
745745

projects/igniteui-angular/core/src/core/utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import type { IgxTheme } from '../services/theme/theme.token';
88
/** @hidden @internal */
99
export const ELEMENTS_TOKEN = /*@__PURE__*/new InjectionToken<boolean>('elements environment');
1010

11+
12+
/**
13+
* Returns true if the element's direction is left-to-right
14+
*
15+
* @hidden @internal
16+
*/
17+
export function isLeftToRight(element: Element): boolean {
18+
return element?.matches(':dir(ltr)') ?? true;
19+
}
20+
1121
/**
1222
* @hidden
1323
*/

projects/igniteui-angular/core/src/services/direction/directionality.spec.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

projects/igniteui-angular/core/src/services/direction/directionality.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.

projects/igniteui-angular/core/src/services/public_api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
export * from './animation/angular-animation-player';
33
export * from './animation/angular-animation-service';
44
export * from './animation/animation';
5-
export { Direction as ɵDirection, DIR_DOCUMENT as ɵDIR_DOCUMENT, IgxDirectionality as ɵIgxDirectionality } from './direction/directionality';
65
export * from './overlay/overlay';
76
export * from './overlay/position';
87
export * from './overlay/scroll';

projects/igniteui-angular/radio/src/radio/radio-group/radio-group.directive.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
booleanAttribute,
1313
effect,
1414
signal,
15-
inject
15+
inject,
16+
ElementRef
1617
} from '@angular/core';
1718
import { ControlValueAccessor, NgControl, Validators } from '@angular/forms';
1819
import { fromEvent, noop, Subject, takeUntil } from 'rxjs';
1920
import { IgxRadioComponent } from '../radio.component';
20-
import { ɵIgxDirectionality } from 'igniteui-angular/core';
21+
import { isLeftToRight } from 'igniteui-angular/core';
2122
import { IChangeCheckboxEventArgs } from 'igniteui-angular/directives';
2223
/**
2324
* Determines the Radio Group alignment
@@ -60,8 +61,8 @@ let nextId = 0;
6061
})
6162
export class IgxRadioGroupDirective implements ControlValueAccessor, OnDestroy, DoCheck {
6263
public ngControl = inject(NgControl, { optional: true, self: true });
63-
private _directionality = inject(ɵIgxDirectionality);
6464
private cdr = inject(ChangeDetectorRef);
65+
private readonly _element = inject<ElementRef<HTMLElement>>(ElementRef);
6566

6667
private _radioButtons = signal<IgxRadioComponent[]>([]);
6768
private _radioButtonsList = new QueryList<IgxRadioComponent>();
@@ -259,7 +260,7 @@ export class IgxRadioGroupDirective implements ControlValueAccessor, OnDestroy,
259260

260261
if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(key)) {
261262
let index = checked ? buttons.indexOf(checked) : -1;
262-
const ltr = this._directionality.value === 'ltr';
263+
const ltr = isLeftToRight(this._element.nativeElement);
263264

264265
switch (key) {
265266
case 'ArrowUp':

projects/igniteui-angular/slider/src/slider/slider.component.spec.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angul
33
import { FormsModule, ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
44
import { By, HammerModule } from '@angular/platform-browser';
55
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
6-
import { ɵDIR_DOCUMENT, ɵIgxDirectionality } from 'igniteui-angular/core';
76
import { UIInteractions, wait } from '../../../test-utils/ui-interactions.spec';
87
import { IgxSliderType, IgxThumbFromTemplateDirective, IgxThumbToTemplateDirective, IRangeSliderValue, TickLabelsOrientation, TicksOrientation } from './slider.common';
98
import { IgxSliderComponent } from './slider.component';
@@ -24,16 +23,8 @@ const SLIDER_TICK_LABELS_HIDDEN_CLASS = 'igx-slider__tick-label--hidden';
2423
const TOP_TO_BOTTOM_TICK_LABLES = '.igx-slider__tick-labels--top-bottom';
2524
const BOTTOM_TO_TOP_TICK_LABLES = '.igx-slider__tick-labels--bottom-top';
2625

27-
interface FakeDoc {
28-
body: { dir?: string };
29-
documentElement: { dir?: string };
30-
}
31-
3226
describe('IgxSlider', () => {
33-
let fakeDoc: FakeDoc;
3427
beforeEach(waitForAsync(() => {
35-
fakeDoc = { body: {}, documentElement: {} };
36-
3728
TestBed.configureTestingModule({
3829
imports: [
3930
NoopAnimationsModule, FormsModule, ReactiveFormsModule, HammerModule,
@@ -49,9 +40,6 @@ describe('IgxSlider', () => {
4940
SliderTemplateFormComponent,
5041
SliderReactiveFormComponent,
5142
SliderWithValueAdjustmentComponent
52-
],
53-
providers: [
54-
{ provide: ɵDIR_DOCUMENT, useFactory: () => fakeDoc }
5543
]
5644
}).compileComponents();
5745
}));
@@ -1732,14 +1720,6 @@ describe('IgxSlider', () => {
17321720
});
17331721

17341722
describe('Slider RTL', () => {
1735-
beforeEach(() => {
1736-
fakeDoc.documentElement.dir = 'rtl';
1737-
});
1738-
1739-
afterEach(() => {
1740-
fakeDoc.documentElement.dir = 'ltr';
1741-
});
1742-
17431723
it('should reflect on the right instead of the left css property of the slider handlers', () => {
17441724
const fix = TestBed.createComponent(SliderRtlComponent);
17451725
fix.detectChanges();
@@ -1748,8 +1728,6 @@ describe('IgxSlider', () => {
17481728
const thumbs = fix.debugElement.queryAll(By.css(THUMB_TAG));
17491729
const labels = fix.debugElement.queryAll(By.css(THUMB_LABEL));
17501730

1751-
expect(inst.dir.rtl).toEqual(true);
1752-
17531731
expect(thumbs[0].nativeElement.style['right']).toEqual(`${fix.componentInstance.value.lower}%`);
17541732
expect(thumbs[1].nativeElement.style['right']).toEqual(`${fix.componentInstance.value.upper}%`);
17551733

@@ -2061,13 +2039,11 @@ describe('IgxSlider', () => {
20612039
@Component({
20622040
selector: 'igx-slider-rtl',
20632041
template: `
2064-
<igx-slider [type]="type" [value]="value"></igx-slider>
2042+
<div dir="rtl"><igx-slider [type]="type" [value]="value"></igx-slider></div>
20652043
`,
20662044
imports: [IgxSliderComponent]
20672045
})
20682046
export class SliderRtlComponent {
2069-
public dir = inject(ɵIgxDirectionality);
2070-
20712047
@ViewChild(IgxSliderComponent)
20722048
public slider: IgxSliderComponent;
20732049

projects/igniteui-angular/slider/src/slider/slider.component.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AfterContentInit, AfterViewInit, ChangeDetectorRef, Component, ContentC
22
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
33
import { animationFrameScheduler, fromEvent, interval, merge, noop, Observable, Subject, timer } from 'rxjs';
44
import { takeUntil, throttle, throttleTime } from 'rxjs/operators';
5-
import { EditorProvider, ɵIgxDirectionality, resizeObservable } from 'igniteui-angular/core';
5+
import { EditorProvider, isLeftToRight, resizeObservable } from 'igniteui-angular/core';
66
import { IgxThumbLabelComponent } from './label/thumb-label.component';
77
import {
88
IgxSliderType, IgxThumbFromTemplateDirective,
@@ -47,7 +47,6 @@ export class IgxSliderComponent implements
4747
private _el = inject(ElementRef);
4848
private _cdr = inject(ChangeDetectorRef);
4949
private _ngZone = inject(NgZone);
50-
private _dir = inject(ɵIgxDirectionality);
5150

5251
/**
5352
* @hidden
@@ -1200,19 +1199,13 @@ export class IgxSliderComponent implements
12001199
return this._el.nativeElement.getBoundingClientRect().width / (this.maxValue - this.minValue) * this.step;
12011200
}
12021201

1203-
// private toggleThumb() {
1204-
// return this.thumbFrom.isActive ?
1205-
// this.thumbTo.nativeElement.focus() :
1206-
// this.thumbFrom.nativeElement.focus();
1207-
// }
1208-
12091202
private valueInRange(value, min = 0, max = 100) {
12101203
return Math.max(Math.min(value, max), min);
12111204
}
12121205

12131206
private positionHandler(thumbHandle: ElementRef, labelHandle: ElementRef, position: number) {
12141207
const percent = `${this.valueToFraction(position) * 100}%`;
1215-
const dir = this._dir.rtl ? 'right' : 'left';
1208+
const dir = !isLeftToRight(this._el.nativeElement) ? 'right' : 'left';
12161209

12171210
if (thumbHandle) {
12181211
thumbHandle.nativeElement.style[dir] = percent;
@@ -1368,7 +1361,8 @@ export class IgxSliderComponent implements
13681361
trackLeftIndention = Math.round((1 / positionGap * fromPosition) * 100);
13691362
}
13701363

1371-
trackLeftIndention = this._dir.rtl ? -trackLeftIndention : trackLeftIndention;
1364+
const rtl = !isLeftToRight(this._el.nativeElement);
1365+
trackLeftIndention = rtl ? -trackLeftIndention : trackLeftIndention;
13721366
this.renderer.setStyle(this.trackRef.nativeElement, 'transform', `scaleX(${positionGap}) translateX(${trackLeftIndention}%)`);
13731367
} else {
13741368
this.renderer.setStyle(this.trackRef.nativeElement, 'transform', `scaleX(${toPosition})`);

0 commit comments

Comments
 (0)