Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit bcff8a6

Browse files
sayriscopybara-github
authored andcommitted
refactor(tooltip): Renaming getters in Tooltip foundation from getIsXXXX to isXXX.
PiperOrigin-RevId: 350404236
1 parent c5e18b0 commit bcff8a6

File tree

4 files changed

+80
-87
lines changed

4 files changed

+80
-87
lines changed

packages/mdc-tooltip/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export class MDCTooltip extends MDCComponent<MDCTooltipFoundation> {
6161
}
6262

6363
initialSyncWithDOM() {
64-
this.isTooltipRich = this.foundation.getIsRich();
65-
this.isTooltipPersistent = this.foundation.getIsPersistent();
64+
this.isTooltipRich = this.foundation.isRich();
65+
this.isTooltipPersistent = this.foundation.isPersistent();
6666

6767
this.handleMouseEnter = () => {
6868
this.foundation.handleAnchorMouseEnter();
@@ -132,7 +132,7 @@ export class MDCTooltip extends MDCComponent<MDCTooltipFoundation> {
132132
}
133133

134134
isShown() {
135-
this.foundation.getIsShown();
135+
this.foundation.isShown();
136136
}
137137

138138
getDefaultFoundation() {

packages/mdc-tooltip/foundation.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
7474
};
7575
}
7676

77-
private isInteractive!: boolean; // assigned in init()
78-
private isRich!: boolean; // assigned in init()
79-
private isPersistent!: boolean; // assigned in init()
80-
private isShown = false;
77+
private interactiveTooltip!: boolean; // assigned in init()
78+
private richTooltip!: boolean; // assigned in init()
79+
private persistentTooltip!: boolean; // assigned in init()
80+
private tooltipShown = false;
8181
private anchorGap = numbers.BOUNDED_ANCHOR_GAP;
8282
private xTooltipPos = XPosition.DETECTED;
8383
private yTooltipPos = YPosition.DETECTED;
@@ -137,28 +137,28 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
137137
}
138138

139139
init() {
140-
this.isRich = this.adapter.hasClass(RICH);
141-
this.isPersistent =
140+
this.richTooltip = this.adapter.hasClass(RICH);
141+
this.persistentTooltip =
142142
this.adapter.getAttribute(attributes.PERSISTENT) === 'true';
143-
this.isInteractive =
143+
this.interactiveTooltip =
144144
!!this.adapter.getAnchorAttribute(attributes.ARIA_EXPANDED) &&
145145
this.adapter.getAnchorAttribute(attributes.ARIA_HASPOPUP) === 'true';
146146
}
147147

148-
getIsShown() {
149-
return this.isShown;
148+
isShown() {
149+
return this.tooltipShown;
150150
}
151151

152-
getIsRich() {
153-
return this.isRich;
152+
isRich() {
153+
return this.richTooltip;
154154
}
155155

156-
getIsPersistent() {
157-
return this.isPersistent;
156+
isPersistent() {
157+
return this.persistentTooltip;
158158
}
159159

160160
handleAnchorMouseEnter() {
161-
if (this.isShown) {
161+
if (this.tooltipShown) {
162162
// Covers the instance where a user hovers over the anchor to reveal the
163163
// tooltip, and then quickly navigates away and then back to the anchor.
164164
// The tooltip should stay visible without animating out and then back in
@@ -201,7 +201,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
201201
}
202202

203203
handleAnchorBlur(evt: FocusEvent) {
204-
if (this.isRich) {
204+
if (this.richTooltip) {
205205
const tooltipContainsRelatedTargetElement =
206206
evt.relatedTarget instanceof HTMLElement &&
207207
this.adapter.tooltipContainsElement(evt.relatedTarget);
@@ -215,7 +215,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
215215
}
216216

217217
handleAnchorClick() {
218-
if (this.isShown) {
218+
if (this.tooltipShown) {
219219
this.hide();
220220
} else {
221221
this.show();
@@ -234,7 +234,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
234234
// being immediately hidden if the tooltip was initially hidden.
235235
// - The click target is within the tooltip element, since clicks
236236
// on the tooltip do not close the tooltip.
237-
if (this.isRich && this.isPersistent &&
237+
if (this.richTooltip && this.persistentTooltip &&
238238
anchorOrTooltipContainsTargetElement) {
239239
return;
240240
}
@@ -297,22 +297,22 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
297297
this.clearHideTimeout();
298298
this.clearShowTimeout();
299299

300-
if (this.isShown) {
300+
if (this.tooltipShown) {
301301
return;
302302
}
303303

304-
this.isShown = true;
304+
this.tooltipShown = true;
305305
const showTooltipOptions = this.parseShowTooltipOptions();
306306
if (!showTooltipOptions.hideFromScreenreader) {
307307
this.adapter.setAttribute('aria-hidden', 'false');
308308
}
309-
if (this.isRich) {
310-
if (this.isInteractive) {
309+
if (this.richTooltip) {
310+
if (this.interactiveTooltip) {
311311
this.adapter.setAnchorAttribute('aria-expanded', 'true');
312312
}
313313
this.adapter.registerEventHandler(
314314
'focusout', this.richTooltipFocusOutHandler);
315-
if (!this.isPersistent) {
315+
if (!this.persistentTooltip) {
316316
this.adapter.registerEventHandler(
317317
'mouseenter', this.richTooltipMouseEnterHandler);
318318
this.adapter.registerEventHandler(
@@ -321,7 +321,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
321321
}
322322
this.adapter.removeClass(HIDE);
323323
this.adapter.addClass(SHOWING);
324-
if (this.isTooltipMultiline() && !this.isRich) {
324+
if (this.isTooltipMultiline() && !this.richTooltip) {
325325
this.adapter.addClass(MULTILINE_TOOLTIP);
326326
}
327327
this.anchorRect = this.adapter.getAnchorBoundingRect();
@@ -346,23 +346,23 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
346346
this.clearHideTimeout();
347347
this.clearShowTimeout();
348348

349-
if (!this.isShown) {
349+
if (!this.tooltipShown) {
350350
return;
351351
}
352352

353353
if (this.frameId) {
354354
cancelAnimationFrame(this.frameId);
355355
}
356356

357-
this.isShown = false;
357+
this.tooltipShown = false;
358358
this.adapter.setAttribute('aria-hidden', 'true');
359359
this.adapter.deregisterEventHandler(
360360
'focusout', this.richTooltipFocusOutHandler);
361-
if (this.isRich) {
362-
if (this.isInteractive) {
361+
if (this.richTooltip) {
362+
if (this.interactiveTooltip) {
363363
this.adapter.setAnchorAttribute('aria-expanded', 'false');
364364
}
365-
if (!this.isPersistent) {
365+
if (!this.persistentTooltip) {
366366
this.adapter.deregisterEventHandler(
367367
'mouseenter', this.richTooltipMouseEnterHandler);
368368
this.adapter.deregisterEventHandler(
@@ -475,7 +475,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
475475
anchorRect: ClientRect, tooltipWidth: number) {
476476
const isLTR = !this.adapter.isRTL();
477477
let startPos, endPos, centerPos: number|undefined;
478-
if (this.isRich) {
478+
if (this.richTooltip) {
479479
startPos = isLTR ? anchorRect.left - tooltipWidth : anchorRect.right;
480480
endPos = isLTR ? anchorRect.right : anchorRect.left - tooltipWidth;
481481
} else {
@@ -484,7 +484,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
484484
centerPos = anchorRect.left + (anchorRect.width - tooltipWidth) / 2;
485485
}
486486

487-
const positionOptions = this.isRich ?
487+
const positionOptions = this.richTooltip ?
488488
this.determineValidPositionOptions(startPos, endPos) :
489489
// For plain tooltips, centerPos is defined
490490
this.determineValidPositionOptions(centerPos!, startPos, endPos);
@@ -503,7 +503,7 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
503503
// If no user position is supplied, rich tooltips default to end pos, then
504504
// start position. Plain tooltips default to center, start, then end.
505505
const possiblePositions =
506-
this.isRich ? [endPos, startPos] : [centerPos, startPos, endPos];
506+
this.richTooltip ? [endPos, startPos] : [centerPos, startPos, endPos];
507507

508508
const validPosition =
509509
possiblePositions.find(pos => positionOptions.has(pos));
@@ -688,10 +688,10 @@ export class MDCTooltipFoundation extends MDCFoundation<MDCTooltipAdapter> {
688688
this.adapter.removeClass(HIDE);
689689
this.adapter.removeClass(HIDE_TRANSITION);
690690

691-
if (this.isRich) {
691+
if (this.richTooltip) {
692692
this.adapter.deregisterEventHandler(
693693
'focusout', this.richTooltipFocusOutHandler);
694-
if (!this.isPersistent) {
694+
if (!this.persistentTooltip) {
695695
this.adapter.deregisterEventHandler(
696696
'mouseenter', this.richTooltipMouseEnterHandler);
697697
this.adapter.deregisterEventHandler(

packages/mdc-tooltip/test/component.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ describe('MDCTooltip', () => {
199199
component.destroy();
200200
});
201201

202-
it('#isShown forwards to MDCFoundation#getIsShown', () => {
202+
it('#isShown forwards to MDCFoundation#isShown', () => {
203203
const {mockFoundation, component} = setupTestWithMockFoundation(fixture);
204204
component.isShown();
205-
expect(mockFoundation.getIsShown).toHaveBeenCalled();
205+
expect(mockFoundation.isShown).toHaveBeenCalled();
206206
component.destroy();
207207
});
208208

packages/mdc-tooltip/test/foundation.test.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ const ANIMATION_FRAME = 1;
4242
function expectTooltipToHaveBeenShown(
4343
foundation: MDCTooltipFoundation,
4444
mockAdapter: jasmine.SpyObj<MDCTooltipAdapter>) {
45-
if (foundation.getIsRich()) {
46-
if (foundation['isInteractive']) {
47-
expect(mockAdapter.setAnchorAttribute)
48-
.toHaveBeenCalledWith('aria-expanded', 'true');
49-
}
45+
if (foundation.isRich() && foundation['interactiveTooltip']) {
46+
expect(mockAdapter.setAnchorAttribute)
47+
.toHaveBeenCalledWith('aria-expanded', 'true');
5048
}
5149

5250
expect(mockAdapter.setAttribute).toHaveBeenCalledWith('aria-hidden', 'false');
@@ -60,11 +58,9 @@ function expectTooltipToHaveBeenShown(
6058
function expectTooltipToHaveBeenHidden(
6159
foundation: MDCTooltipFoundation,
6260
mockAdapter: jasmine.SpyObj<MDCTooltipAdapter>) {
63-
if (foundation.getIsRich()) {
64-
if (foundation['isInteractive']) {
65-
expect(mockAdapter.setAnchorAttribute)
66-
.toHaveBeenCalledWith('aria-expanded', 'false');
67-
}
61+
if (foundation.isRich() && foundation['interactiveTooltip']) {
62+
expect(mockAdapter.setAnchorAttribute)
63+
.toHaveBeenCalledWith('aria-expanded', 'false');
6864
}
6965

7066
expect(mockAdapter.setAttribute).toHaveBeenCalledWith('aria-hidden', 'true');
@@ -79,11 +75,9 @@ function expectTooltipToHaveBeenHidden(
7975
function expectTooltipNotToHaveBeenHidden(
8076
foundation: MDCTooltipFoundation,
8177
mockAdapter: jasmine.SpyObj<MDCTooltipAdapter>) {
82-
if (foundation.getIsRich()) {
83-
if (foundation['isInteractive']) {
84-
expect(mockAdapter.setAnchorAttribute)
85-
.not.toHaveBeenCalledWith('aria-expanded', 'false');
86-
}
78+
if (foundation.isRich() && foundation['interactiveTooltip']) {
79+
expect(mockAdapter.setAnchorAttribute)
80+
.not.toHaveBeenCalledWith('aria-expanded', 'false');
8781
}
8882

8983
expect(mockAdapter.setAttribute)
@@ -143,48 +137,48 @@ describe('MDCTooltipFoundation', () => {
143137
]);
144138
});
145139

146-
it('#getIsRich returns false for plain tooltip', () => {
140+
it('#isRich returns false for plain tooltip', () => {
147141
const {foundation, mockAdapter} = setUpFoundationTest(MDCTooltipFoundation);
148142
mockAdapter.hasClass.withArgs(CssClasses.RICH).and.returnValue(false);
149143
foundation.init();
150144

151-
expect(foundation.getIsRich()).toBeFalse();
145+
expect(foundation.isRich()).toBeFalse();
152146
});
153147

154-
it('#getIsRich returns true for rich tooltip', () => {
148+
it('#isRich returns true for rich tooltip', () => {
155149
const {foundation} =
156150
setUpFoundationTestForRichTooltip(MDCTooltipFoundation);
157151

158-
expect(foundation.getIsRich()).toBeTrue();
152+
expect(foundation.isRich()).toBeTrue();
159153
});
160154

161-
it('#getIsPersistent returns false for default rich tooltip', () => {
155+
it('#isPersistent returns false for default rich tooltip', () => {
162156
const {foundation} =
163157
setUpFoundationTestForRichTooltip(MDCTooltipFoundation);
164158

165-
expect(foundation.getIsPersistent()).toBeFalse();
159+
expect(foundation.isPersistent()).toBeFalse();
166160
});
167161

168-
it('#getIsPersistent returns true for persistent rich tooltip', () => {
162+
it('#isPersistent returns true for persistent rich tooltip', () => {
169163
const {foundation} = setUpFoundationTestForRichTooltip(
170164
MDCTooltipFoundation, {isPersistent: true});
171165

172-
expect(foundation.getIsPersistent()).toBeTrue();
166+
expect(foundation.isPersistent()).toBeTrue();
173167
});
174168

175-
it('#getIsShown returns true if the tooltip is currently shown', () => {
169+
it('#isShown returns true if the tooltip is currently shown', () => {
176170
const {foundation} = setUpFoundationTest(MDCTooltipFoundation);
177171
foundation.show();
178172

179-
expect(foundation.getIsShown()).toBeTrue();
173+
expect(foundation.isShown()).toBeTrue();
180174
});
181175

182-
it('#getIsShown returns false if the tooltip is currently hidden', () => {
176+
it('#isShown returns false if the tooltip is currently hidden', () => {
183177
const {foundation} = setUpFoundationTest(MDCTooltipFoundation);
184178
foundation.show();
185179
foundation.hide();
186180

187-
expect(foundation.getIsShown()).toBeFalse();
181+
expect(foundation.isShown()).toBeFalse();
188182
});
189183

190184
it('#show modifies tooltip element so it is shown', () => {
@@ -849,7 +843,7 @@ describe('MDCTooltipFoundation', () => {
849843
const {foundation, mockAdapter} = setUpFoundationTestForRichTooltip(
850844
MDCTooltipFoundation, {isPersistent: true});
851845

852-
expect(foundation.isShown).toBe(false);
846+
expect(foundation.isShown()).toBeFalse();
853847
foundation.handleAnchorClick();
854848

855849
expectTooltipToHaveBeenShown(foundation, mockAdapter);
@@ -1038,7 +1032,7 @@ describe('MDCTooltipFoundation', () => {
10381032
expect(foundation.hideTimeout).toEqual(null);
10391033
expect(mockAdapter.setAttribute)
10401034
.not.toHaveBeenCalledWith('aria-hidden', 'true');
1041-
expect(foundation.isShown).toBeTrue();
1035+
expect(foundation.isShown()).toBeTrue();
10421036
});
10431037

10441038
it('#hide clears any pending showTimeout', () => {
@@ -1571,28 +1565,27 @@ describe('MDCTooltipFoundation', () => {
15711565
.toHaveBeenCalledWith('resize', jasmine.any(Function));
15721566
});
15731567

1574-
it('#destroy removes the event listeners for default rich tooltips',
1575-
() => {
1576-
const {foundation, mockAdapter} =
1577-
setUpFoundationTestForRichTooltip(MDCTooltipFoundation);
1568+
it('#destroy removes the event listeners for default rich tooltips', () => {
1569+
const {foundation, mockAdapter} =
1570+
setUpFoundationTestForRichTooltip(MDCTooltipFoundation);
15781571

1579-
foundation.destroy();
1572+
foundation.destroy();
15801573

1581-
expect(mockAdapter.deregisterEventHandler)
1582-
.toHaveBeenCalledWith('focusout', jasmine.any(Function));
1583-
expect(mockAdapter.deregisterEventHandler)
1584-
.toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
1585-
expect(mockAdapter.deregisterEventHandler)
1586-
.toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
1587-
expect(mockAdapter.deregisterDocumentEventHandler)
1588-
.toHaveBeenCalledWith('click', jasmine.any(Function));
1589-
expect(mockAdapter.deregisterDocumentEventHandler)
1590-
.toHaveBeenCalledWith('keydown', jasmine.any(Function));
1591-
expect(mockAdapter.deregisterWindowEventHandler)
1592-
.toHaveBeenCalledWith('scroll', jasmine.any(Function));
1593-
expect(mockAdapter.deregisterWindowEventHandler)
1594-
.toHaveBeenCalledWith('resize', jasmine.any(Function));
1595-
});
1574+
expect(mockAdapter.deregisterEventHandler)
1575+
.toHaveBeenCalledWith('focusout', jasmine.any(Function));
1576+
expect(mockAdapter.deregisterEventHandler)
1577+
.toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
1578+
expect(mockAdapter.deregisterEventHandler)
1579+
.toHaveBeenCalledWith('mouseleave', jasmine.any(Function));
1580+
expect(mockAdapter.deregisterDocumentEventHandler)
1581+
.toHaveBeenCalledWith('click', jasmine.any(Function));
1582+
expect(mockAdapter.deregisterDocumentEventHandler)
1583+
.toHaveBeenCalledWith('keydown', jasmine.any(Function));
1584+
expect(mockAdapter.deregisterWindowEventHandler)
1585+
.toHaveBeenCalledWith('scroll', jasmine.any(Function));
1586+
expect(mockAdapter.deregisterWindowEventHandler)
1587+
.toHaveBeenCalledWith('resize', jasmine.any(Function));
1588+
});
15961589

15971590
it('#destroy removes the event listeners for persistent rich tooltips',
15981591
() => {

0 commit comments

Comments
 (0)