@mrktg-common/internal-ui 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Combobox.js CHANGED
@@ -7,6 +7,7 @@ import { FixedPortal } from './portal.js';
7
7
  import { Spinner } from './Spinner.js';
8
8
  import { cx } from './cx.js';
9
9
  import { devError } from './devWarn.js';
10
+ import { openingActive, stepActive } from './activeOption.js';
10
11
  const GAP = 4;
11
12
  const EDGE = 12;
12
13
  const defaultEmptyText = (query) => `No options match “${query}”`;
@@ -19,6 +20,7 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
19
20
  // Кнопка открывает весь список, ввод — отфильтрованный
20
21
  const [filtering, setFiltering] = useState(false);
21
22
  const [active, setActive] = useState(0);
23
+ const [activeSource, setActiveSource] = useState('none');
22
24
  const [listStyle, setListStyle] = useState({ visibility: 'hidden' });
23
25
  const rootRef = useRef(null);
24
26
  const inputRef = useRef(null);
@@ -83,14 +85,18 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
83
85
  // В jsdom прокрутки нет: тесты потребителей не должны падать на ней
84
86
  document.getElementById(optionId(active))?.scrollIntoView?.({ block: 'nearest' });
85
87
  });
86
- const show = ({ filter }) => {
88
+ const show = ({ filter, byKeys }) => {
87
89
  if (failed)
88
90
  return;
89
91
  if (!open)
90
92
  setListStyle({ visibility: 'hidden' });
91
93
  setFiltering(filter);
92
94
  const current = all.findIndex((option) => option.value === value);
93
- setActive(filter ? 0 : Math.max(0, current));
95
+ if (filter)
96
+ setActive(0);
97
+ else
98
+ setActive(byKeys ? openingActive(current) : current);
99
+ setActiveSource(filter || byKeys ? 'keys' : 'none');
94
100
  setOpen(true);
95
101
  };
96
102
  const commit = (next) => {
@@ -108,16 +114,18 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
108
114
  if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
109
115
  event.preventDefault();
110
116
  if (!visible) {
111
- show({ filter: false });
117
+ show({ filter: false, byKeys: true });
112
118
  return;
113
119
  }
114
120
  if (shown.length === 0)
115
121
  return;
116
- const step = event.key === 'ArrowDown' ? 1 : -1;
117
- setActive((current) => (current + step + shown.length) % shown.length);
122
+ const checked = shown.findIndex((option) => option.value === value);
123
+ setActive(stepActive({ active, source: activeSource, checked, step: event.key === 'ArrowDown' ? 1 : -1, count: shown.length }));
124
+ setActiveSource('keys');
118
125
  }
119
126
  else if (event.key === 'Enter') {
120
- const option = visible && !loading ? shown[active] : undefined;
127
+ // Список, открытый кликом, без активного пункта: Enter оставляет текст как есть
128
+ const option = visible && !loading && activeSource !== 'none' ? shown[active] : undefined;
121
129
  if (visible)
122
130
  event.preventDefault();
123
131
  if (option === undefined) {
@@ -137,11 +145,11 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
137
145
  setOpen(false);
138
146
  }
139
147
  };
140
- const activeOption = visible && !loading && shown[active] !== undefined ? optionId(active) : undefined;
148
+ const activeOption = visible && !loading && activeSource !== 'none' && shown[active] !== undefined ? optionId(active) : undefined;
141
149
  return (_jsxs("div", { className: cx('combo', className), ref: rootRef, children: [_jsx("input", { ref: inputRef, id: id, type: "text", className: controlClass({ size, invalid, mono }), role: "combobox", "aria-autocomplete": "list", "aria-expanded": visible, "aria-controls": visible ? listId : undefined, "aria-activedescendant": activeOption, "aria-invalid": invalid || undefined, autoComplete: "off", value: value, placeholder: placeholder, disabled: disabled, onChange: (event) => {
142
150
  committed.current = null;
143
151
  onChange(event.target.value);
144
- show({ filter: true });
152
+ show({ filter: true, byKeys: true });
145
153
  }, onKeyDown: handleKeyDown, onBlur: () => {
146
154
  setOpen(false);
147
155
  commit(value);
@@ -152,12 +160,19 @@ export function Combobox({ id, value, onChange, options, groups, loading = false
152
160
  if (visible)
153
161
  setOpen(false);
154
162
  else
155
- show({ filter: false });
163
+ show({ filter: false, byKeys: false });
156
164
  }, children: _jsx(ChevronDown, { className: "ic", "aria-hidden": true }) })), visible && (_jsx(FixedPortal, { children: _jsx("div", { ref: listRef, className: "pop pop-scroll", style: listStyle, role: "listbox", id: listId, "aria-labelledby": id, children: loading ? (_jsx("div", { className: "menu-empty", role: "status", children: _jsxs("span", { className: "row", style: { justifyContent: 'center' }, children: [_jsx(Spinner, { size: "sm" }), "Loading\u2026"] }) })) : shown.length === 0 ? (_jsxs("div", { className: "menu-empty", children: [_jsx("span", { className: "strong", children: emptyText(query) }), _jsx("span", { className: "hint", children: "You can keep it as typed." })] })) : (shownGroups.map((group, groupIndex) => {
157
165
  const rows = group.options.map((option) => {
158
166
  const index = shown.indexOf(option);
159
167
  const isCurrent = option.value === value;
160
- return (_jsxs("div", { id: optionId(index), role: "option", "aria-selected": isCurrent, className: cx('menu-item', index === active && 'is-hover'), onMouseDown: (event) => event.preventDefault(), onMouseEnter: () => setActive(index), onClick: () => pick(option), children: [_jsx("span", { className: "trunc", children: filtering ? _jsx(Highlight, { text: option.value, query: query }) : option.value }), option.trailing !== undefined && _jsx("span", { className: "trail", children: option.trailing }), isCurrent && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, option.value));
168
+ return (_jsxs("div", { id: optionId(index), role: "option", "aria-selected": isCurrent, className: cx('menu-item', index === active && activeSource === 'keys' && 'is-active'), onMouseDown: (event) => event.preventDefault(),
169
+ // Только настоящее движение мыши: список, открытый или прокрученный под курсором, пункт не меняет
170
+ onMouseMove: () => {
171
+ if (index === active && activeSource === 'pointer')
172
+ return;
173
+ setActive(index);
174
+ setActiveSource('pointer');
175
+ }, onClick: () => pick(option), children: [_jsx("span", { className: "trunc", children: filtering ? _jsx(Highlight, { text: option.value, query: query }) : option.value }), option.trailing !== undefined && _jsx("span", { className: "trail", children: option.trailing }), isCurrent && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, option.value));
161
176
  });
162
177
  if (group.label === null)
163
178
  return _jsx(Fragment, { children: rows }, `group-${groupIndex}`);
@@ -6,6 +6,7 @@ import { cx } from './cx.js';
6
6
  import { buttonClass } from './buttonClass.js';
7
7
  import { controlClass } from './Field.js';
8
8
  import { FixedPortal } from './portal.js';
9
+ import { openingActive, stepActive } from './activeOption.js';
9
10
  const GAP = 4;
10
11
  const EDGE = 12;
11
12
  /**
@@ -24,6 +25,7 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
24
25
  ];
25
26
  const items = shownGroups.flatMap((group) => group.items);
26
27
  const [active, setActive] = useState(0);
28
+ const [activeSource, setActiveSource] = useState('none');
27
29
  const rootRef = useRef(null);
28
30
  const buttonRef = useRef(null);
29
31
  const menuRef = useRef(null);
@@ -84,10 +86,12 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
84
86
  // В jsdom прокрутки нет: тесты потребителей не должны падать на ней
85
87
  menuRef.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView?.({ block: 'nearest' });
86
88
  }, [open, active]);
87
- const openMenu = () => {
89
+ const openMenu = ({ byKeys }) => {
88
90
  setMenuStyle({ visibility: 'hidden' });
89
91
  setQuery('');
90
- setActive(Math.max(0, items.findIndex((item) => item.value === value)));
92
+ const checked = items.findIndex((item) => item.value === value);
93
+ setActive(byKeys ? openingActive(checked) : checked);
94
+ setActiveSource(byKeys ? 'keys' : 'none');
91
95
  setOpen(true);
92
96
  };
93
97
  const close = () => {
@@ -104,7 +108,7 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
104
108
  if (!open) {
105
109
  if (event.target === buttonRef.current && (event.key === 'ArrowDown' || event.key === 'ArrowUp')) {
106
110
  event.preventDefault();
107
- openMenu();
111
+ openMenu({ byKeys: true });
108
112
  }
109
113
  return;
110
114
  }
@@ -115,13 +119,17 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
115
119
  }
116
120
  else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
117
121
  event.preventDefault();
118
- const step = event.key === 'ArrowDown' ? 1 : -1;
119
- setActive((current) => (current + step + items.length) % Math.max(items.length, 1));
122
+ const checked = items.findIndex((item) => item.value === value);
123
+ setActive(stepActive({ active, source: activeSource, checked, step: event.key === 'ArrowDown' ? 1 : -1, count: items.length }));
124
+ setActiveSource('keys');
120
125
  }
121
126
  else if (event.key === 'Enter') {
122
127
  event.preventDefault();
123
- const item = items[active];
124
- if (item !== undefined)
128
+ // Список, открытый кликом, без активного пункта: Enter закрывает без изменений
129
+ const item = activeSource === 'none' ? undefined : items[active];
130
+ if (item === undefined)
131
+ close();
132
+ else
125
133
  choose(item);
126
134
  }
127
135
  else if (event.key === 'Tab') {
@@ -129,22 +137,37 @@ export function SelectMenu({ id, value, groups, onChange, placeholder, autoFocus
129
137
  }
130
138
  else if (search === undefined && event.key.length === 1 && !event.metaKey && !event.ctrlKey && !event.altKey) {
131
139
  const letter = event.key.toLowerCase();
132
- const order = [...items.slice(active + 1), ...items.slice(0, active + 1)];
140
+ const from = activeSource === 'none' ? items.findIndex((item) => item.value === value) : active;
141
+ const order = [...items.slice(from + 1), ...items.slice(0, from + 1)];
133
142
  const match = order.find((item) => item.label.toLowerCase().startsWith(letter));
134
- if (match !== undefined)
143
+ if (match !== undefined) {
135
144
  setActive(items.indexOf(match));
145
+ setActiveSource('keys');
146
+ }
136
147
  }
137
148
  };
149
+ const optionId = (index) => `${listId}-option-${index}`;
150
+ // Только когда активный пункт есть: у списка, открытого кликом, его нет
151
+ const activeOption = open && activeSource !== 'none' && items[active] !== undefined ? optionId(active) : undefined;
138
152
  const triggerClass = filter === undefined
139
153
  ? controlClass({ size, invalid }, 'select-btn')
140
154
  : buttonClass({ variant: 'secondary', size, active: filter.active });
141
- return (_jsxs("div", { className: cx('anchor', className), style: filter === undefined ? { display: 'flex' } : undefined, ref: rootRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { ref: buttonRef, id: id, type: "button", className: triggerClass, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listId : undefined, "aria-invalid": invalid || undefined, disabled: disabled, onClick: () => (open ? setOpen(false) : openMenu()), ...aria, children: [filter !== undefined ? filter.label : selected === undefined ? _jsx("span", { className: "muted trunc", children: placeholder ?? value }) : _jsx(ItemContent, { item: selected }), _jsx(ChevronDown, { className: cx('ic', 'chev', filter !== undefined && 'ic-sm'), "aria-hidden": true })] }), open && (_jsx(FixedPortal, { children: _jsxs("div", { ref: menuRef, className: "pop pop-scroll", style: menuStyle, role: "listbox", id: listId, "aria-labelledby": id, children: [search !== undefined && (_jsx("div", { className: "menu-search", children: _jsxs("label", { className: "with-icon", children: [_jsx(SearchIcon, { className: "ic", "aria-hidden": true }), _jsx("span", { className: "sr-only", children: search.label }), _jsx("input", { ref: searchRef, className: "control control-sm", value: query, placeholder: search.placeholder, onChange: (event) => {
155
+ return (_jsxs("div", { className: cx('anchor', className), style: filter === undefined ? { display: 'flex' } : undefined, ref: rootRef, onKeyDown: handleKeyDown, children: [_jsxs("button", { ref: buttonRef, id: id, type: "button", className: triggerClass, "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": open ? listId : undefined, "aria-activedescendant": search === undefined ? activeOption : undefined, "aria-invalid": invalid || undefined, disabled: disabled, onClick: () => (open ? setOpen(false) : openMenu({ byKeys: false })), ...aria, children: [filter !== undefined ? filter.label : selected === undefined ? _jsx("span", { className: "muted trunc", children: placeholder ?? value }) : _jsx(ItemContent, { item: selected }), _jsx(ChevronDown, { className: cx('ic', 'chev', filter !== undefined && 'ic-sm'), "aria-hidden": true })] }), open && (_jsx(FixedPortal, { children: _jsxs("div", { ref: menuRef, className: "pop pop-scroll", style: menuStyle, role: "listbox", id: listId, "aria-labelledby": id, children: [search !== undefined && (_jsx("div", { className: "menu-search", children: _jsxs("label", { className: "with-icon", children: [_jsx(SearchIcon, { className: "ic", "aria-hidden": true }), _jsx("span", { className: "sr-only", children: search.label }), _jsx("input", { ref: searchRef, className: "control control-sm", value: query, placeholder: search.placeholder, "aria-controls": listId, "aria-activedescendant": activeOption, onChange: (event) => {
142
156
  setQuery(event.target.value);
143
157
  setActive(0);
158
+ setActiveSource('keys');
144
159
  } })] }) })), items.length === 0 && (_jsxs("div", { className: "menu-empty", children: [_jsxs("span", { className: "strong", children: ["Nothing matches \u201C", query.trim(), "\u201D"] }), _jsx("span", { className: "hint", children: "Try a shorter name." })] })), shownGroups.map((group, groupIndex) => (_jsxs("div", { role: "group", "aria-label": group.label ?? undefined, children: [group.label !== null && _jsx("div", { className: "menu-label", children: group.label }), group.note !== undefined && (_jsxs("div", { className: "menu-note", children: [_jsx(TriangleAlert, { className: "ic ic-sm", "aria-hidden": true }), _jsx("span", { children: group.note })] })), group.items.map((item) => {
145
160
  const index = items.indexOf(item);
146
161
  const isSelected = item.value === value;
147
- return (_jsxs("button", { type: "button", role: "option", "data-index": index, tabIndex: -1, "aria-selected": isSelected, "aria-disabled": item.disabled || undefined, className: cx('menu-item', index === active && 'is-hover'), onMouseEnter: () => setActive(index), onClick: () => choose(item), children: [_jsx(ItemContent, { item: item }), item.trailing !== undefined && _jsx("span", { className: "trail", children: item.trailing }), isSelected && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, item.value));
162
+ return (_jsxs("button", { type: "button", role: "option", id: optionId(index), "data-index": index, tabIndex: -1, "aria-selected": isSelected, "aria-disabled": item.disabled || undefined, className: cx('menu-item', index === active && activeSource === 'keys' && 'is-active'),
163
+ // Только настоящее движение мыши: список, открытый или прокрученный под курсором, пункт не меняет.
164
+ // Выключенный пункт под мышью не меняется
165
+ onMouseMove: () => {
166
+ if (item.disabled || (index === active && activeSource === 'pointer'))
167
+ return;
168
+ setActive(index);
169
+ setActiveSource('pointer');
170
+ }, onClick: () => choose(item), children: [_jsx(ItemContent, { item: item }), item.trailing !== undefined && _jsx("span", { className: "trail", children: item.trailing }), isSelected && _jsx(Check, { className: "ic check", "aria-hidden": true })] }, item.value));
148
171
  })] }, group.label ?? `group-${groupIndex}`)))] }) }))] }));
149
172
  }
150
173
  function ItemContent({ item }) {
@@ -0,0 +1,14 @@
1
+ /** Откуда активный пункт: с клавиатуры — полоса is-active, от мыши — только :hover, нет — список открыт кликом */
2
+ export type TActiveSource = 'keys' | 'pointer' | 'none';
3
+ interface IStepActiveArgs {
4
+ active: number;
5
+ source: TActiveSource;
6
+ checked: number;
7
+ step: 1 | -1;
8
+ count: number;
9
+ }
10
+ /** Пункт после ↓ / ↑: от активного, а если его нет — от отмеченного галочкой; без галочки ↓ берёт первый, ↑ последний */
11
+ export declare function stepActive({ active, source, checked, step, count }: IStepActiveArgs): number;
12
+ /** Пункт при открытии стрелкой: текущее значение, иначе первый */
13
+ export declare function openingActive(checked: number): number;
14
+ export {};
@@ -0,0 +1,14 @@
1
+ // Активный пункт Select menu и Combobox: тот, что возьмёт Enter (карточки, раздел «Active option»)
2
+ /** Пункт после ↓ / ↑: от активного, а если его нет — от отмеченного галочкой; без галочки ↓ берёт первый, ↑ последний */
3
+ export function stepActive({ active, source, checked, step, count }) {
4
+ if (count === 0)
5
+ return 0;
6
+ const from = source === 'none' ? checked : active;
7
+ if (from < 0 || from >= count)
8
+ return step === 1 ? 0 : count - 1;
9
+ return (from + step + count) % count;
10
+ }
11
+ /** Пункт при открытии стрелкой: текущее значение, иначе первый */
12
+ export function openingActive(checked) {
13
+ return Math.max(0, checked);
14
+ }
@@ -223,8 +223,13 @@
223
223
  .menu-item > .ic { color: var(--text-muted); }
224
224
  .menu-item:hover, .menu-item.is-hover, .menu-item:focus-visible, .menu-item.is-focus { outline: none; background: var(--bg-subtle); }
225
225
  .menu-item:focus-visible, .menu-item.is-focus { box-shadow: inset 0 0 0 2px var(--accent); }
226
+ /* Active option of Select menu and Combobox (aria-activedescendant): focus stays in the field or the trigger,
227
+ so the keyboard position is a bar on the left edge, not a second focus ring. */
228
+ .menu-item.is-active { background: var(--bg-subtle); box-shadow: inset 3px 0 0 var(--accent); }
226
229
  .menu-item.is-danger, .menu-item.is-danger > .ic { color: var(--danger-text); }
227
230
  .menu-item:disabled, .menu-item[aria-disabled='true'] { color: var(--text-muted); opacity: 0.55; cursor: not-allowed; background: none; }
231
+ /* The keyboard mark on an off item keeps its 3:1: the row isn't dimmed while the keyboard is on it. */
232
+ .menu-item[aria-disabled='true']:focus-visible, .menu-item.is-focus[aria-disabled='true'], .menu-item.is-active[aria-disabled='true'] { opacity: 1; }
228
233
  /* Selected option: check on the right, as on the agreed Publish window. */
229
234
  .menu-item > .check { margin-left: auto; color: var(--accent-text); }
230
235
  .menu-item[aria-selected='true'] { font-weight: 500; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrktg-common/internal-ui",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "Общий интерфейс внутренних инструментов маркетинга (Landings Admin, LP Constructor): токены, классы компонентов и тонкие React-обёртки над ними.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -2,7 +2,7 @@
2
2
  "name": "Internal ui",
3
3
  "version": 1,
4
4
  "meta": {
5
- "release": "1.11.0",
5
+ "release": "1.12.0",
6
6
  "source": "lp-constructor src/styles/tokens.css + Landings Admin admin.css, merged 2026-10-12"
7
7
  },
8
8
  "color": {
@@ -103,7 +103,7 @@
103
103
  "light": "#2f6fed",
104
104
  "dark": "#5b8dff"
105
105
  },
106
- "usage": "Primary button, solid badge, count pill, focus border, active tab line, selection outline, progress. A UI mark: 4.6:1 on surface light, 5.0:1 dark."
106
+ "usage": "Primary button, solid badge, count pill, focus border, active tab line, active option bar in Select menu and Combobox, selection outline, progress. A UI mark: 4.6:1 on surface light, 5.0:1 dark."
107
107
  },
108
108
  {
109
109
  "name": "accent-hover",