Skip to content

Commit 452a96b

Browse files
committed
feat(services): rtl service
1 parent c4c45b0 commit 452a96b

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

projects/coreui-angular/src/lib/services/public_api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export { LocalStorageService } from './local-storage.service';
55
export { InMemoryStorageService } from './in-memory-storage.service';
66
export { ColorModeService, ColorMode } from './color-mode.service';
77
export { UIDService } from './uid.service';
8+
export { RtlService } from './rtl.service';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { RtlService } from './rtl.service';
4+
5+
describe('RtlService', () => {
6+
let service: RtlService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(RtlService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { inject, Injectable } from '@angular/core';
2+
import { DOCUMENT } from '@angular/common';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class RtlService {
8+
readonly #document = inject(DOCUMENT);
9+
10+
isRTL(element?: HTMLElement | null): boolean {
11+
if (element) {
12+
return element.closest('[dir="rtl"]') !== null;
13+
}
14+
15+
return this.#document?.documentElement?.dir === 'rtl' || this.#document?.body?.dir === 'rtl';
16+
}
17+
}

0 commit comments

Comments
 (0)