|
85 | 85 |
|
86 | 86 | static get observers() {
|
87 | 87 | return [
|
88 |
| - '_updateVisibleChildColumns(_childColumns)', |
89 |
| - '_childColumnsChanged(_childColumns)', |
90 | 88 | '_groupFrozenChanged(frozen, _rootColumns)',
|
91 |
| - '_groupHiddenChanged(hidden, _rootColumns)', |
92 |
| - '_visibleChildColumnsChanged(_visibleChildColumns)', |
| 89 | + '_groupHiddenChanged(hidden)', |
93 | 90 | '_colSpanChanged(_colSpan, _headerCell, _footerCell)',
|
94 | 91 | '_groupOrderChanged(_order, _rootColumns)',
|
95 | 92 | '_groupReorderStatusChanged(_reorderStatus, _rootColumns)',
|
|
117 | 114 | */
|
118 | 115 | _columnPropChanged(path, value) {
|
119 | 116 | if (path === 'hidden') {
|
120 |
| - this._preventHiddenCascade = true; |
| 117 | + // Prevent synchronization of the hidden state to child columns. |
| 118 | + // If the group is currently auto-hidden, and one column is made visible, |
| 119 | + // we don't want the other columns to become visible as well. |
| 120 | + this._preventHiddenSynchronization = true; |
121 | 121 | this._updateVisibleChildColumns(this._childColumns);
|
122 |
| - this._preventHiddenCascade = false; |
| 122 | + this._preventHiddenSynchronization = false; |
123 | 123 | }
|
124 | 124 |
|
125 | 125 | if (/flexGrow|width|hidden|_childColumns/.test(path)) {
|
|
191 | 191 |
|
192 | 192 | /** @private */
|
193 | 193 | _updateVisibleChildColumns(childColumns) {
|
194 |
| - this._visibleChildColumns = Array.prototype.filter.call(childColumns, col => !col.hidden); |
195 |
| - } |
196 |
| - |
197 |
| - /** @private */ |
198 |
| - _childColumnsChanged(childColumns) { |
199 |
| - if (!this._autoHidden && this.hidden) { |
200 |
| - Array.prototype.forEach.call(childColumns, column => column.hidden = true); |
201 |
| - this._updateVisibleChildColumns(childColumns); |
202 |
| - } |
| 194 | + this._visibleChildColumns = Array.prototype.filter.call(childColumns, (col) => !col.hidden); |
| 195 | + this._colSpan = this._visibleChildColumns.length; |
| 196 | + this._updateAutoHidden(); |
203 | 197 | }
|
204 | 198 |
|
205 | 199 | /** @protected */
|
|
233 | 227 | }
|
234 | 228 |
|
235 | 229 | /** @private */
|
236 |
| - _groupHiddenChanged(hidden, rootColumns) { |
237 |
| - if (rootColumns && !this._preventHiddenCascade) { |
238 |
| - this._ignoreVisibleChildColumns = true; |
239 |
| - rootColumns.forEach(column => column.hidden = hidden); |
240 |
| - this._ignoreVisibleChildColumns = false; |
| 230 | + _groupHiddenChanged(hidden) { |
| 231 | + // When initializing the hidden property, only sync hidden state to columns |
| 232 | + // if group is actually hidden. Otherwise, we could override a hidden column |
| 233 | + // to be visible. |
| 234 | + // We always want to run this though if the property is actually changed. |
| 235 | + if (hidden || this.__groupHiddenInitialized) { |
| 236 | + this._synchronizeHidden(); |
241 | 237 | }
|
| 238 | + this.__groupHiddenInitialized = true; |
| 239 | + } |
242 | 240 |
|
243 |
| - this._columnPropChanged('hidden'); |
| 241 | + /** @private */ |
| 242 | + _updateAutoHidden() { |
| 243 | + const wasAutoHidden = this._autoHidden; |
| 244 | + this._autoHidden = (this._visibleChildColumns || []).length === 0; |
| 245 | + // Only modify hidden state if group was auto-hidden, or becomes auto-hidden |
| 246 | + if (wasAutoHidden || this._autoHidden) { |
| 247 | + this.hidden = this._autoHidden; |
| 248 | + } |
244 | 249 | }
|
245 | 250 |
|
246 | 251 | /** @private */
|
247 |
| - _visibleChildColumnsChanged(visibleChildColumns) { |
248 |
| - this._colSpan = visibleChildColumns.length; |
249 |
| - |
250 |
| - if (!this._ignoreVisibleChildColumns) { |
251 |
| - if (visibleChildColumns.length === 0) { |
252 |
| - this._autoHidden = this.hidden = true; |
253 |
| - } else if (this.hidden && this._autoHidden) { |
254 |
| - this._autoHidden = this.hidden = false; |
255 |
| - } |
| 252 | + _synchronizeHidden() { |
| 253 | + if (this._childColumns && !this._preventHiddenSynchronization) { |
| 254 | + this._childColumns.forEach((column) => (column.hidden = this.hidden)); |
256 | 255 | }
|
257 | 256 | }
|
258 | 257 |
|
|
283 | 282 | if (info.addedNodes.filter(this._isColumnElement).length > 0 ||
|
284 | 283 | info.removedNodes.filter(this._isColumnElement).length > 0) {
|
285 | 284 |
|
286 |
| - this._preventHiddenCascade = true; |
| 285 | + // Prevent synchronization of the hidden state to child columns. |
| 286 | + // If the group is currently auto-hidden, and a visible column is added, |
| 287 | + // we don't want the other columns to become visible as well. |
| 288 | + this._preventHiddenSynchronization = true; |
287 | 289 | this._rootColumns = this._getChildColumns(this);
|
288 | 290 | this._childColumns = this._rootColumns;
|
289 |
| - this._preventHiddenCascade = false; |
| 291 | + this._updateVisibleChildColumns(this._childColumns); |
| 292 | + this._preventHiddenSynchronization = false; |
290 | 293 |
|
291 | 294 | // Update the column tree with microtask timing to avoid shady style scope issues
|
292 | 295 | Polymer.Async.microTask.run(() => {
|
|
0 commit comments