// Manual Column Sorting @mixin output { .handsontable { // The label is the sort button, so it must not fill the header cell: the bare header around it // is what selects a column and starts a drag. Sized to its text, so only the text and the // indicator sort on click. // Three classes beat the `_base.scss` rule that makes the label fill the row - class count is // compared before element count - so the structural path is not repeated here. .colHeader.columnSorting.sortAction { box-sizing: border-box; flex-grow: 0; // Centers the label; `htLeft`/`htRight` move the box instead, below. margin-inline: auto; // Never collapse in a narrow column, never grow past the header. min-width: min(calc(var(--ht-icon-size, 16px) + 8px), 100%); max-width: 100%; // Hands the absolutely positioned indicators to `.relative`, so they stay pinned to the // header edge while the label shrinks away from it. Clicking one still sorts: an event on a // pseudo-element targets the element that owns it. position: static; // `.relative`'s padding box is the containing block for the multi-column-sorting sequence // number, which is still a `::after` pseudo-element - the sort-direction arrow is a real // `.ht-sort-indicator` element now and positions itself below, without this margin. &::after { margin-inline: var(--ht-sort-indicator-offset); margin-inline-end: var(--ht-sort-indicator-offset-end); } } // `text-align` used to place the text inside a full-width label. The label is now sized to its // text, so the alignment has to move the box or every aligned header renders centered. Physical // margins, because `htLeft`/`htRight` are physical in either direction. Matched as an ancestor: // `headerClassName` puts the class on `.relative`, code that sets it by hand puts it on the // `th`. .htLeft .colHeader.columnSorting.sortAction { margin-left: 0; margin-right: auto; } .htRight .colHeader.columnSorting.sortAction { margin-left: auto; margin-right: 0; } // The distances the indicator needs, kept as custom properties so the alignment, direction and // ghost-table rules can override them without having to out-rank every rule that reads them. // Internal to this file, not theme tokens. th .relative { // Distance from the header edge. --ht-sort-indicator-offset: var(--ht-cell-horizontal-padding); // The same, on the inline-end side that a trailing button shares. --ht-sort-indicator-offset-end: var(--ht-cell-horizontal-padding); // Room the container holds back for the indicator. --ht-sort-indicator-reserve: var(--ht-cell-horizontal-padding); // The same, inline-end only - split so the button case can drop it on its own. --ht-sort-indicator-reserve-end: var(--ht-sort-indicator-reserve); // Room held open before a trailing button for the indicator to sit in. --ht-header-button-slot: calc(var(--ht-icon-size, 16px) + 2px); // The narrowest a header with a menu button and a sort indicator can be before the indicator // has to give way: the indicator's reserve, the gap, the button's slot and the cell padding // at the other edge, with the label already gone. A step, not a ramp - see the narrow-header // block below. --ht-header-indicator-min-width: calc(2 * var(--ht-cell-horizontal-padding) + 2 * var(--ht-icon-size, 16px) + 6px); // The same, measured on the content box, which is what a percentage `column-gap` resolves // against. --ht-header-indicator-min-content-width: calc(2 * var(--ht-icon-size, 16px) + 6px); // The gap between the label and the menu button as the header currently lays it out; the label's // narrow-header `min-width` leaves room for it. 2px is the base gap (`_base.scss`). --ht-header-gap: 2px; } // Step the indicator over a trailing icon button. What has to be cleared is the button's border // box, which overhangs its slot by half of (hit area - icon): `_dropdown-menu.scss` sizes it to // the hit area and pulls it back with a uniform negative margin. Derived from those tokens // rather than a fixed number - the classic theme uses a smaller icon with the same hit area. .relative.has-header-button { --ht-sort-indicator-offset-end: calc( var(--ht-cell-horizontal-padding) + var(--ht-icon-size, 16px) + (var(--ht-icon-button-hit-area-size, 24px) - var(--ht-icon-size, 16px)) * 0.5 ); // The gap below already separates the label from the indicator here. Reserving as well drags // the button - the last flex item - left over the indicator, which it then hides (`z-index: 1`). --ht-sort-indicator-reserve-end: var(--ht-cell-horizontal-padding); } // Hold the indicator's slot open between the label and the button. Done with the gap, not a // margin on the button: the button carries a uniform negative margin that a one-sided override // would cancel, widening the header. .relative.has-sort-indicator.has-header-button { // 2px is the base gap between header items (`_base.scss`). Below the minimum content width the // slot closes: `(100% - minimum) * 1000` is a large negative length there and a large positive // one above, so `clamp()` turns it into a step between the base gap and the full slot. --ht-header-gap: clamp( 2px, calc((100% - var(--ht-header-indicator-min-content-width)) * 1000 + 2px), calc(2px + var(--ht-header-button-slot)) ); column-gap: var(--ht-header-gap); } // Room for the indicator, held on the container rather than as padding on the label - padding // would grow the box that sorts on click. The side follows where the indicator is pinned: // inline-end, unless the alignment class points against the direction (`htRight` in LTR, // `htLeft` in RTL). .relative.has-sort-indicator { --ht-sort-indicator-reserve: calc(var(--ht-cell-horizontal-padding) + var(--ht-icon-size, 16px) + 2px); padding-inline-end: var(--ht-sort-indicator-reserve-end); } // Two selectors, because the room is held on the container itself: `headerClassName` puts the // alignment class on that same `.relative`, code that sets it by hand puts it on the `th`. .relative.htRight.has-sort-indicator, .htRight .relative.has-sort-indicator { padding-inline-start: var(--ht-sort-indicator-reserve); padding-inline-end: var(--ht-cell-horizontal-padding); // The indicator is opposite the button here, so nothing needs holding open. --ht-header-button-slot: 0px; } // With a button, the reserve at the start edge closes in a narrow header together with the // indicator it holds the room for. The RTL block below carries a rule of the same specificity for // `htRight` that has to win over this one, and does so only by coming later in the file. .relative.htRight.has-sort-indicator.has-header-button, .htRight .relative.has-sort-indicator.has-header-button { padding-inline-start: clamp( var(--ht-cell-horizontal-padding), calc((100% - var(--ht-header-indicator-min-width)) * 1000 + var(--ht-cell-horizontal-padding)), var(--ht-sort-indicator-reserve) ); } // Narrow header with a menu button (DEV-158). As the column narrows, the header gives things up // in this order: the label text, then the sort indicator, and the menu button last - it is the // only way into the menu, and the narrowest column (`manualColumnResize`'s floor) is sized to hold // it. The label may only collapse next to a button: with no button, `min-width` above keeps the // sortable label open in a narrow column. .relative.has-header-button .colHeader.columnSorting.sortAction { min-width: min( calc(var(--ht-icon-size, 16px) + 8px), max(0px, calc(100% - var(--ht-icon-size, 16px) - 2px - var(--ht-header-gap))) ); } // The indicator (`.ht-sort-indicator`) and the multi-column sort order (the label's `::after`) // are pinned to `.relative`, so a percentage resolves against its padding box. Capped to zero // below the minimum width the header needs to show them next to the button; a step, like the // gap above. `overflow` clips an external icon renderer's inline content with the box. .relative.has-header-button.has-sort-indicator > .ht-sort-indicator { max-width: clamp( 0px, calc((100% - var(--ht-header-indicator-min-width)) * 1000), var(--ht-icon-size, 16px) ); overflow: hidden; } .relative.has-header-button.has-sort-indicator .colHeader.columnSorting.sortAction { &::after { max-width: clamp(0px, calc((100% - var(--ht-header-indicator-min-width)) * 1000), 8px); overflow: hidden; } } .columnSorting:not(.indicatorDisabled) { position: relative; &.sortAction:hover { text-decoration: none; cursor: pointer; } } // The sort-direction glyph: a real `` element, // created by `syncIcon()` in `columnSorting.ts` as a sibling of the `.colHeader` label inside // `.relative`, not a `::before` pseudo-element on the label - so it positions against the // container, using the same offset custom properties the old pseudo-element read, plus the same // literal 2px edge margin the old pseudo's `right: 2px`/`left: 2px` carried on top of its own // `margin-inline-end`. `--ht-sort-indicator-reserve` (above) is calibrated against that same // total (`padding + icon-size + 2px`), so dropping the 2px here measurably narrows the gap to a // trailing dropdown-menu button by 2px - confirmed empirically: without it, the icon overlapped // both the label and the button on an auto-sized `has-header-button` column. Logical properties // resolve the `[dir="rtl"]` mirroring on their own; only the `htRight`/`htLeft` alignment-class // swap below still needs stating by hand, same as the old pseudo did. th .relative > .ht-sort-indicator { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-end: calc(var(--ht-sort-indicator-offset-end) + 2px); // The old `::before` belonged to the label, so a press on the arrow sorted. The base // `.ht-icon` is `pointer-events: none`; this slot takes its hits back, and // `wasClickableHeaderClicked()` (`columnSorting.ts`) accepts the slot class as a target. pointer-events: auto; } // Same affordance the label shows: the arrow sits outside the label's box, so it cannot // inherit the label's `cursor`. The `:hover` half is not redundant. Blink's touch adjustment // snaps a tap to the nearest node it considers tappable - one with a click listener, a // focusable one, or one whose style is affected by `:hover`/`:active`. Sorting and the column menu both listen on ancestors, so // without a hover-dependent rule the `` is not tappable and a tap on the arrow is retargeted // to the adjacent dropdown-menu button, opening the menu instead of sorting. In 18.1 the arrow // was the label's `::before`, and the label has a `:hover` rule (above). .columnSorting.sortAction ~ .ht-sort-indicator { cursor: pointer; &:hover { cursor: pointer; } } // A right-aligned column's label sits at the container's start edge (see `.htRight // .colHeader.columnSorting.sortAction` above), so the indicator moves to the start edge with // it - the mirror of the `has-sort-indicator` padding swap above. .relative.htRight > .ht-sort-indicator, .htRight .relative > .ht-sort-indicator { inset-inline-end: auto; inset-inline-start: calc(var(--ht-sort-indicator-offset) + 2px); } } [dir="rtl"] { .handsontable { // In RTL the indicator sits inline-end by default, so `htRight` matches the default and has // to undo the LTR rule above. .relative.htRight.has-sort-indicator, .htRight .relative.has-sort-indicator { padding-inline-start: var(--ht-cell-horizontal-padding); padding-inline-end: var(--ht-sort-indicator-reserve-end); // Back on the button's side, so the slot is needed again. --ht-header-button-slot: calc(var(--ht-icon-size, 16px) + 2px); } // `htLeft` is the class that points against the direction here - the mirror of `htRight` in // LTR. .relative.htLeft.has-sort-indicator, .htLeft .relative.has-sort-indicator { padding-inline-start: var(--ht-sort-indicator-reserve); padding-inline-end: var(--ht-cell-horizontal-padding); // Opposite the button, so nothing needs holding open. --ht-header-button-slot: 0px; } // Same closing reserve as in LTR, on the side opposite the button. .relative.htLeft.has-sort-indicator.has-header-button, .htLeft .relative.has-sort-indicator.has-header-button { padding-inline-start: clamp( var(--ht-cell-horizontal-padding), calc((100% - var(--ht-header-indicator-min-width)) * 1000 + var(--ht-cell-horizontal-padding)), var(--ht-sort-indicator-reserve) ); } // Undoes the LTR `htRight` swap above: in RTL, `htRight` matches the default inline-end // position, so the indicator stays there. .relative.htRight > .ht-sort-indicator, .htRight .relative > .ht-sort-indicator { inset-inline-start: auto; inset-inline-end: calc(var(--ht-sort-indicator-offset-end) + 2px); } // The mirror of the LTR `htRight` swap - `htLeft` is the class that points against the // direction in RTL. .relative.htLeft > .ht-sort-indicator, .htLeft .relative > .ht-sort-indicator { inset-inline-end: auto; inset-inline-start: calc(var(--ht-sort-indicator-offset) + 2px); } } } // The indicator is a real element now and, like in the real table, is absolutely // positioned against `.relative` - so it contributes nothing to the ghost table's own flow-based // measurement either. The offsets it would be positioned by are zeroed here for the same reason // they always were: counting them on top of the reserve below would make every auto-sized column // wider than the real table renders it. .htGhostTable .htCore .relative { --ht-sort-indicator-offset: 0px; --ht-sort-indicator-offset-end: 0px; --ht-header-button-slot: 0px; } // The reserve stays: it stands in for the space the indicator takes in the real table, and the // measurement needs it. The exception is a header with a trailing button, which // `_multi-column-sorting.scss` already gives its own gap here. .htGhostTable .htCore .relative.has-header-button { --ht-sort-indicator-reserve: var(--ht-cell-horizontal-padding); --ht-sort-indicator-reserve-end: var(--ht-cell-horizontal-padding); } // The narrow-header rules above resolve percentages against the header's width, which the ghost // table does not have yet - it is measuring that width. Keep its sizing exactly as it was, so // `autoColumnSize` does not change. .htGhostTable .htCore .relative.has-header-button .colHeader.columnSorting.sortAction { min-width: min(calc(var(--ht-icon-size, 16px) + 8px), 100%); &::after { max-width: none; } } .htGhostTable .htCore .relative.has-header-button.has-sort-indicator > .ht-sort-indicator { max-width: none; } .htGhostTable .htCore .relative.has-sort-indicator.has-header-button { --ht-header-gap: calc(2px + var(--ht-header-button-slot)); column-gap: var(--ht-header-gap); } // `getColHeader` clones the header through the same `afterGetColHeader` hook the real // table uses, so `.ht-sort-indicator` DOES end up in the ghost table's markup too - but it stays // absolutely positioned there exactly as in the real table (see the base `.ht-sort-indicator` rule // above), so it contributes nothing to the ghost row's own flow-based width, same as the // `::before` pseudo-element it replaced never did either. Measured empirically: dropping this rule // (trusting the real `` to reserve the space by itself) undersized the column - the icon // overlapped the label and the trailing dropdown button rendered outside the header's right edge. // This `*` box is what stands in for the width a header-button column would otherwise get from the // real table's `column-gap` (`--ht-header-button-slot`, zeroed above because ghost headers are not // laid out with that gap at all). .htGhostTable .htCore span.colHeader.columnSorting:not(.indicatorDisabled)::before { content: "*"; display: inline-block; position: relative; /* The multi-line header and header with longer text need more padding to not hide arrow, we make header wider in `GhostTable` to make some space for arrow which is positioned absolutely in the main table */ padding-inline-end: calc(var(--ht-icon-size, 16px) + 2px); } // Before icons became elements the real table's `.sortAction::before` rule (the glyph's box) also // matched the ghost pseudo-element above and gave it `width: var(--ht-icon-size, 16px)`. The // measured reserve of a clickable header was therefore `icon-size + (icon-size + 2px)`, not the // `*` glyph's own width plus the padding. That rule is gone with the pseudo-element glyph, so the // width is restated here - dropping it measured every sortable header with a menu button about // 10px narrower than 18.1 (the visual suite caught it on every nested-headers demo). It stays // scoped to `.sortAction`, as the 18.1 rule was: a `headerAction: false` label measures the `*` // glyph's own width, so its auto-sized column keeps its 18.1 width. .htGhostTable .htCore span.colHeader.columnSorting.sortAction:not(.indicatorDisabled)::before { width: var(--ht-icon-size, 16px); } }