Skip to content

Commit ed246ce

Browse files
committed
fix double controls
1 parent 8d80420 commit ed246ce

11 files changed

Lines changed: 255 additions & 65 deletions

‎dist/data-grid.js‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4440,7 +4440,7 @@ class ResponsiveGrid extends base_plugin_default {
44404440
}
44414441
}
44424442
extendColumns(columns) {
4443-
if (!this.grid.options.responsive || !this.grid.options.responsiveToggle) {
4443+
if (!this.grid.options.responsive || !this.grid.options.responsiveToggle || this._sharesDisclosure()) {
44444444
return;
44454445
}
44464446
columns.unshift({
@@ -4549,7 +4549,7 @@ class ResponsiveGrid extends base_plugin_default {
45494549
}, 0);
45504550
const requiredWidth = (visibleItems) => {
45514551
let total = fixedWidth;
4552-
if (grid.options.responsiveToggle && items.some(({ column }) => column?.responsiveHidden)) {
4552+
if (grid.options.responsiveToggle && !this._sharesDisclosure() && items.some(({ column }) => column?.responsiveHidden)) {
45534553
total += RESPONSIVE_TOGGLE_WIDTH;
45544554
}
45554555
for (const { th } of visibleItems) {
@@ -4663,6 +4663,17 @@ class ResponsiveGrid extends base_plugin_default {
46634663
previous = td;
46644664
}
46654665
}
4666+
_sharesDisclosure() {
4667+
return Boolean(this.grid.options.responsiveToggle) && typeof this.grid.options.rowDetails === "function" && Boolean(this.grid.getPlugin("RowDetails"));
4668+
}
4669+
followDisclosure(tr, expanded) {
4670+
if (!this._sharesDisclosure()) {
4671+
return;
4672+
}
4673+
this.blockObserver();
4674+
this._setRowExpanded(tr, expanded);
4675+
this.unblockObserver();
4676+
}
46664677
_setToggleIcon(tr, expanded) {
46674678
const control = tr.querySelector(`.${RESPONSIVE_CLASS}-toggle-control`);
46684679
const rowIndex = Number.parseInt(tr.dataset.rowIndex ?? "0", 10) || 0;
@@ -5404,6 +5415,10 @@ class RowDetails extends base_plugin_default {
54045415
if (button) {
54055416
this._syncToggle(button, row, rowIndex, expanded);
54065417
}
5418+
const responsive = this.grid.getPlugin("ResponsiveGrid");
5419+
if (typeof responsive?.followDisclosure === "function") {
5420+
responsive.followDisclosure(tr, expanded);
5421+
}
54075422
const id = this._detailId(rowIndex);
54085423
const current = document.getElementById(id);
54095424
if (!expanded) {

‎dist/data-grid.min.js‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/types/plugins/responsive-grid.d.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ declare class ResponsiveGrid extends BasePlugin {
8181
* @param {HTMLTableRowElement} tr
8282
*/
8383
_canonicalizeRow(tr: HTMLTableRowElement): void;
84+
/**
85+
* True when the row details column already provides a disclosure control
86+
* for every row: responsive then yields, rather than rendering a second
87+
* identical chevron next to it, and follows that control instead.
88+
*
89+
* Both facts are required: the option carries the intent, the plugin does
90+
* the rendering. If either is missing (ex: a non standard registration
91+
* name), responsive keeps its own toggle — the safe fallback is a visible
92+
* control, never hidden values with no way to reach them.
93+
* @returns {Boolean}
94+
*/
95+
_sharesDisclosure(): boolean;
96+
/**
97+
* Follow the shared disclosure control: the row details toggle governs the
98+
* whole expansion surface of its row, responsive values included. No-op
99+
* unless responsive has yielded its own toggle, so an explicit
100+
* `responsiveToggle: false` keeps its section governed by
101+
* `responsiveStartOpen` alone.
102+
* @public
103+
* @param {HTMLTableRowElement} tr
104+
* @param {Boolean} expanded
105+
*/
106+
followDisclosure(tr: HTMLTableRowElement, expanded: boolean): void;
84107
/**
85108
* Reflect the expanded state on the toggle column icon (no-op when there is
86109
* no toggle column, i.e. `responsiveToggle: false`).

‎dist/types/plugins/responsive-grid.d.ts.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/types/plugins/row-details.d.ts.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/plugins/responsive-grid.js‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ResponsiveGrid extends BasePlugin {
9191
* @param {import("../data-grid.js").Column[]} columns
9292
*/
9393
extendColumns(columns) {
94-
if (!this.grid.options.responsive || !this.grid.options.responsiveToggle) {
94+
if (!this.grid.options.responsive || !this.grid.options.responsiveToggle || this._sharesDisclosure()) {
9595
return;
9696
}
9797
columns.unshift({
@@ -271,7 +271,11 @@ class ResponsiveGrid extends BasePlugin {
271271
}, 0);
272272
const requiredWidth = (/** @type {Array<any>} */ visibleItems) => {
273273
let total = fixedWidth;
274-
if (grid.options.responsiveToggle && items.some(({ column }) => column?.responsiveHidden)) {
274+
if (
275+
grid.options.responsiveToggle &&
276+
!this._sharesDisclosure() &&
277+
items.some(({ column }) => column?.responsiveHidden)
278+
) {
275279
total += RESPONSIVE_TOGGLE_WIDTH;
276280
}
277281
for (const { th } of visibleItems) {
@@ -429,6 +433,44 @@ class ResponsiveGrid extends BasePlugin {
429433
}
430434
}
431435

436+
/**
437+
* True when the row details column already provides a disclosure control
438+
* for every row: responsive then yields, rather than rendering a second
439+
* identical chevron next to it, and follows that control instead.
440+
*
441+
* Both facts are required: the option carries the intent, the plugin does
442+
* the rendering. If either is missing (ex: a non standard registration
443+
* name), responsive keeps its own toggle — the safe fallback is a visible
444+
* control, never hidden values with no way to reach them.
445+
* @returns {Boolean}
446+
*/
447+
_sharesDisclosure() {
448+
return (
449+
Boolean(this.grid.options.responsiveToggle) &&
450+
typeof this.grid.options.rowDetails === "function" &&
451+
Boolean(this.grid.getPlugin("RowDetails"))
452+
);
453+
}
454+
455+
/**
456+
* Follow the shared disclosure control: the row details toggle governs the
457+
* whole expansion surface of its row, responsive values included. No-op
458+
* unless responsive has yielded its own toggle, so an explicit
459+
* `responsiveToggle: false` keeps its section governed by
460+
* `responsiveStartOpen` alone.
461+
* @public
462+
* @param {HTMLTableRowElement} tr
463+
* @param {Boolean} expanded
464+
*/
465+
followDisclosure(tr, expanded) {
466+
if (!this._sharesDisclosure()) {
467+
return;
468+
}
469+
this.blockObserver();
470+
this._setRowExpanded(tr, expanded);
471+
this.unblockObserver();
472+
}
473+
432474
/**
433475
* Reflect the expanded state on the toggle column icon (no-op when there is
434476
* no toggle column, i.e. `responsiveToggle: false`).

‎src/plugins/row-details.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ class RowDetails extends BasePlugin {
164164
if (button) {
165165
this._syncToggle(button, row, rowIndex, expanded);
166166
}
167+
168+
// The toggle governs the whole expansion surface of the row, so a
169+
// responsive section that has no control of its own follows it. Told
170+
// before the detail row is inserted: the responsive child row then
171+
// already sits right after the data row, which is where it belongs.
172+
// The dependency is one way on purpose — revealing responsive values
173+
// is cheap, rendering application details is not.
174+
const responsive = /** @type {any} */ (this.grid.getPlugin("ResponsiveGrid"));
175+
if (typeof responsive?.followDisclosure === "function") {
176+
responsive.followDisclosure(tr, expanded);
177+
}
178+
167179
const id = this._detailId(rowIndex);
168180
const current = document.getElementById(id);
169181
if (!expanded) {

0 commit comments

Comments
 (0)