Skip to content

Commit 69b553a

Browse files
fix: fixes component parent/child registration. ensures shouldRegister matches previous configuration.
1 parent 1aea46c commit 69b553a

File tree

9 files changed

+88
-83
lines changed

9 files changed

+88
-83
lines changed

addon/components/paper-button.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ export default class PaperButton extends Focusable {
3434
constructor(owner, args) {
3535
super(owner, args);
3636

37-
this.shouldRegister = this.args.shouldRegister || false;
37+
this.shouldRegister = this.args.shouldRegister ?? false;
3838
this.skipProxy = this.args.skipProxy || false;
39-
if (this.shouldRegister) {
40-
assert(
41-
'A parent component should be supplied to <PaperButton> when shouldRegister=true',
42-
this.args.parentComponent
43-
);
44-
this.parent = this.args.parentComponent;
39+
40+
let parentComponent = this.args.parentComponent;
41+
if (parentComponent && this.shouldRegister) {
42+
this.parent = parentComponent;
4543
}
4644
}
4745

@@ -53,8 +51,9 @@ export default class PaperButton extends Focusable {
5351
this.element = element;
5452
this.registerListeners(element);
5553

56-
if (this.shouldRegister) {
57-
this.parent.registerChild(this);
54+
let parent = this.parent;
55+
if (parent && this.shouldRegister) {
56+
parent.registerChild(this);
5857
}
5958
}
6059

@@ -76,8 +75,9 @@ export default class PaperButton extends Focusable {
7675
willDestroy() {
7776
super.willDestroy(...arguments);
7877

79-
if (this.shouldRegister) {
80-
this.parent.unregisterChild(this);
78+
let parent = this.parent;
79+
if (parent && this.shouldRegister) {
80+
parent.unregisterChild(this);
8181
}
8282
}
8383

addon/components/paper-checkbox.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,12 @@ export default class PaperCheckbox extends Focusable {
5151
super(owner, args);
5252

5353
this.labelId = `${guidFor(args)}-label`;
54-
this.shouldRegister = this.args.shouldRegister || false;
54+
this.shouldRegister = this.args.shouldRegister ?? false;
5555
this.skipProxy = this.args.skipProxy || false;
5656

57-
if (this.shouldRegister) {
58-
assert(
59-
'A parent component should be supplied to <PaperCheckbox> when shouldRegister=true',
60-
this.args.parentComponent
61-
);
62-
this.parent = this.args.parentComponent;
57+
let parentComponent = this.args.parentComponent;
58+
if (parentComponent && this.shouldRegister) {
59+
this.parent = parentComponent;
6360
}
6461

6562
assert(
@@ -76,8 +73,9 @@ export default class PaperCheckbox extends Focusable {
7673
this.element = element;
7774
this.registerListeners(element);
7875

79-
if (this.shouldRegister) {
80-
this.parent.registerChild(this);
76+
let parent = this.parent;
77+
if (parent && this.shouldRegister) {
78+
parent.registerChild(this);
8179
}
8280
}
8381

@@ -96,8 +94,9 @@ export default class PaperCheckbox extends Focusable {
9694
willDestroy() {
9795
super.willDestroy(...arguments);
9896

99-
if (this.shouldRegister) {
100-
this.parent.unregisterChild(this);
97+
let parent = this.parent;
98+
if (parent && this.shouldRegister) {
99+
parent.unregisterChild(this);
101100
}
102101
}
103102

addon/components/paper-form.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
this.inputComponent
1010
parentComponent=this
1111
onValidityChange=this.localOnValidityChange
12+
shouldRegister=true
1213
)
1314
submit-button=(component this.submitButtonComponent type='submit')
1415
select=(component
1516
this.selectComponent
1617
parentComponent=this
1718
onValidityChange=this.localOnValidityChange
19+
shouldRegister=true
1820
)
1921
autocomplete=(component
2022
this.autocompleteComponent

addon/components/paper-input.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export default class PaperInput extends Focusable {
3636
* @type {HTMLInputElement}
3737
* @private
3838
*/
39-
#inputElement;
39+
inputElement;
4040
/**
4141
* The parent this component is bound to.
4242
*
4343
* @type {PaperRadioGroup|PaperForm|PaperItem|PaperTabs}
4444
* @private
4545
*/
46-
#parent;
46+
parent;
4747
/**
4848
* Marks whether the component should register itself to the supplied parent.
4949
*
@@ -97,6 +97,7 @@ export default class PaperInput extends Focusable {
9797
this.args.elementId || this.args.inputElementId || guidFor(this);
9898
this.inputElementId = this.args.inputElementId || `input-${elementId}`;
9999
this.lineHeight = this.args.lineHeight || null;
100+
this.shouldRegister = this.args.shouldRegister ?? true;
100101

101102
// Construct Input Validation and pass through of custom attributes.
102103
this.validation = new Validation(
@@ -109,12 +110,9 @@ export default class PaperInput extends Focusable {
109110
this.args.isTouched
110111
);
111112

112-
if (this.shouldRegister) {
113-
assert(
114-
'A parent component should be supplied to <PaperInput> when shouldRegister=true',
115-
this.args.parentComponent
116-
);
117-
this.#parent = this.args.parentComponent;
113+
let parentComponent = this.args.parentComponent;
114+
if (parentComponent && this.shouldRegister) {
115+
this.parent = parentComponent;
118116
}
119117

120118
assert(
@@ -132,7 +130,7 @@ export default class PaperInput extends Focusable {
132130
this.registerListeners(element);
133131

134132
let inputElement = element.querySelector('input, textarea');
135-
this.#inputElement = inputElement;
133+
this.inputElement = inputElement;
136134
this.validation.didInsertNode(inputElement);
137135

138136
// setValue ensures that the input value is the same as this.value
@@ -143,8 +141,9 @@ export default class PaperInput extends Focusable {
143141
window.addEventListener('resize', this.growTextarea.bind(this));
144142
}
145143

146-
if (this.shouldRegister) {
147-
this.#parent.registerChild(this);
144+
let parent = this.parent;
145+
if (parent && this.shouldRegister) {
146+
parent.registerChild(this);
148147
}
149148
}
150149

@@ -180,8 +179,9 @@ export default class PaperInput extends Focusable {
180179
willDestroy() {
181180
super.willDestroy(...arguments);
182181

183-
if (this.shouldRegister) {
184-
this.#parent.unregisterChild(this);
182+
let parent = this.parent;
183+
if (parent && this.shouldRegister) {
184+
parent.unregisterChild(this);
185185
}
186186
}
187187

@@ -307,7 +307,7 @@ export default class PaperInput extends Focusable {
307307
*/
308308
growTextarea() {
309309
if (this.args.textarea) {
310-
let inputElement = this.#inputElement;
310+
let inputElement = this.inputElement;
311311

312312
inputElement.classList.add('md-no-flex');
313313
inputElement.setAttribute('rows', '1');
@@ -318,7 +318,7 @@ export default class PaperInput extends Focusable {
318318
let lineHeight = this.lineHeight;
319319
if (!lineHeight) {
320320
inputElement.style.minHeight = '0';
321-
lineHeight = this.#inputElement.clientHeight;
321+
lineHeight = this.inputElement.clientHeight;
322322
inputElement.style.minHeight = null;
323323
}
324324
if (lineHeight) {
@@ -372,8 +372,8 @@ export default class PaperInput extends Focusable {
372372
// normalize falsy values to empty string
373373
value = isEmpty(value) ? '' : value;
374374

375-
if (this.#inputElement.value !== value) {
376-
this.#inputElement.value = value;
375+
if (this.inputElement.value !== value) {
376+
this.inputElement.value = value;
377377
}
378378

379379
// Calculate Input Validity

addon/components/paper-radio-proxiable.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import PaperRadio from './paper-radio';
88
* @extends PaperRadioBase
99
*/
1010
export default class PaperRadioProxiable extends PaperRadio {
11+
constructor(owner, args) {
12+
super(owner, args);
13+
14+
this.shouldRegister = this.args.shouldRegister ?? false;
15+
}
16+
1117
processProxy() {
1218
this.onClick();
1319
}

addon/components/paper-radio.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ export default class PaperRadio extends PaperRadioBase {
3030
super(owner, args);
3131

3232
this.skipProxy = this.args.skipProxy || false;
33-
this.shouldRegister = this.args.shouldRegister || false;
34-
if (this.shouldRegister) {
35-
assert(
36-
'A parent component should be supplied to <PaperRadio> when shouldRegister=true',
37-
this.args.parentComponent
38-
);
39-
this.parent = this.args.parentComponent;
33+
this.shouldRegister = this.args.shouldRegister ?? true;
34+
35+
let parentComponent = this.args.parentComponent;
36+
if (parentComponent && this.shouldRegister) {
37+
this.parent = parentComponent;
4038
}
4139
}
4240

@@ -47,16 +45,18 @@ export default class PaperRadio extends PaperRadioBase {
4745
@action didInsertNode(element) {
4846
super.didInsertNode(element);
4947

50-
if (this.shouldRegister) {
51-
this.parent.registerChild(this);
48+
let parent = this.parent;
49+
if (parent && this.shouldRegister) {
50+
parent.registerChild(this);
5251
}
5352
}
5453

5554
willDestroy() {
5655
super.willDestroy(...arguments);
5756

58-
if (this.shouldRegister) {
59-
this.parent.unregisterChild(this);
57+
let parent = this.parent;
58+
if (parent && this.shouldRegister) {
59+
parent.unregisterChild(this);
6060
}
6161
}
6262
}

addon/components/paper-select/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class PaperSelect extends Component {
4141
* @type {PaperRadioGroup|PaperForm|PaperItem|PaperTabs}
4242
* @private
4343
*/
44-
#parent;
44+
parent;
4545
/**
4646
* Marks whether the component should register itself to the supplied parent.
4747
*
@@ -68,6 +68,7 @@ export default class PaperSelect extends Component {
6868

6969
this.didAnimateScale = false;
7070
this.isFocused = false;
71+
this.shouldRegister = this.args.shouldRegister ?? true;
7172

7273
const elementId =
7374
this.args.elementId || this.args.inputElementId || guidFor(this);
@@ -83,12 +84,9 @@ export default class PaperSelect extends Component {
8384
this.args.isTouched
8485
);
8586

86-
if (this.shouldRegister) {
87-
assert(
88-
'A parent component should be supplied to <PaperInput> when shouldRegister=true',
89-
this.args.parentComponent
90-
);
91-
this.#parent = this.args.parentComponent;
87+
let parentComponent = this.args.parentComponent;
88+
if (parentComponent && this.shouldRegister) {
89+
this.parent = parentComponent;
9290
}
9391

9492
assert(
@@ -106,8 +104,9 @@ export default class PaperSelect extends Component {
106104
// setValue ensures that the input value is the same as this.value
107105
this.validation.value = this.args.selected;
108106

109-
if (this.shouldRegister) {
110-
this.#parent.registerChild(this);
107+
let parent = this.parent;
108+
if (parent && this.shouldRegister) {
109+
parent.registerChild(this);
111110
}
112111
}
113112

@@ -140,8 +139,9 @@ export default class PaperSelect extends Component {
140139
willDestroy() {
141140
super.willDestroy(...arguments);
142141

143-
if (this.shouldRegister) {
144-
this.#parent.unregisterChild(this);
142+
let parent = this.parent;
143+
if (parent && this.shouldRegister) {
144+
parent.unregisterChild(this);
145145
}
146146
}
147147

addon/components/paper-switch.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,13 @@ export default class PaperSwitch extends Focusable {
6060
constructor(owner, args) {
6161
super(owner, args);
6262

63-
this.shouldRegister = this.args.shouldRegister || false;
63+
this.shouldRegister = this.args.shouldRegister ?? false;
6464
this.skipProxy = this.args.skipProxy || false;
6565
this.toggle = this.args.toggle || false;
6666

67-
if (this.shouldRegister) {
68-
assert(
69-
'A parent component should be supplied to <PaperSwitch> when shouldRegister=true',
70-
this.args.parentComponent
71-
);
72-
this.parent = this.args.parentComponent;
67+
let parentComponent = this.args.parentComponent;
68+
if (parentComponent && this.shouldRegister) {
69+
this.parent = parentComponent;
7370
}
7471

7572
assert(
@@ -86,8 +83,9 @@ export default class PaperSwitch extends Focusable {
8683
this.element = element;
8784
this.registerListeners(element);
8885

89-
if (this.shouldRegister) {
90-
this.parent.registerChild(this);
86+
let parent = this.parent;
87+
if (parent && this.shouldRegister) {
88+
parent.registerChild(this);
9189
}
9290

9391
// Only setup if the switch is not disabled
@@ -118,8 +116,9 @@ export default class PaperSwitch extends Focusable {
118116
willDestroy() {
119117
super.willDestroy(...arguments);
120118

121-
if (this.shouldRegister) {
122-
this.parent.unregisterChild(this);
119+
let parent = this.parent;
120+
if (parent && this.shouldRegister) {
121+
parent.unregisterChild(this);
123122
}
124123
}
125124

0 commit comments

Comments
 (0)