@evoke-platform/ui-components 1.9.0-dev.0 → 1.9.0-dev.1

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.
@@ -1,7 +1,7 @@
1
1
  import cleanDeep from 'clean-deep';
2
2
  import { cloneDeep, debounce, isEmpty, isNil } from 'lodash';
3
3
  import Handlebars from 'no-eval-handlebars';
4
- import React, { useCallback, useEffect, useState } from 'react';
4
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { Close } from '../../../../../icons';
6
6
  import { Autocomplete, Button, Dialog, IconButton, Link, ListItem, Paper, TextField, Tooltip, Typography, } from '../../../../core';
7
7
  import { Box } from '../../../../layout';
@@ -18,6 +18,7 @@ export const ObjectPropertyInput = (props) => {
18
18
  const [openOptions, setOpenOptions] = useState(false);
19
19
  const [layout, setLayout] = useState();
20
20
  const [layoutLoaded, setLayoutLoaded] = useState(false);
21
+ const listboxRef = useRef(null);
21
22
  const DEFAULT_CREATE_ACTION = '_create';
22
23
  const hasValue = instance?.[property.id]?.id || selectedInstance?.id;
23
24
  useEffect(() => {
@@ -208,17 +209,31 @@ export const ObjectPropertyInput = (props) => {
208
209
  }, noOptionsText: 'No options available', renderOption: (props, option) => {
209
210
  const isAddNew = option.value === '__new__';
210
211
  return (React.createElement(ListItem, { ...props, key: props.id, sx: {
211
- ...(isAddNew ? { borderTop: '1px solid rgba(145, 158, 171, 0.24)' } : {}),
212
+ ...(isAddNew
213
+ ? {
214
+ borderTop: '1px solid rgba(145, 158, 171, 0.24)',
215
+ position: 'sticky',
216
+ bottom: 0,
217
+ backgroundColor: 'white',
218
+ '&:hover': {
219
+ backgroundColor: '#f5f5f5 !important',
220
+ },
221
+ '&.Mui-focused': {
222
+ backgroundColor: '#f5f5f5 !important',
223
+ },
224
+ }
225
+ : {}),
212
226
  } },
213
227
  React.createElement(Box, null,
214
228
  React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px' } }, option.label),
215
- layout?.secondaryTextExpression ? (React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px', color: '#637381' } }, compileExpression(layout?.secondaryTextExpression, options.find((o) => o.id === option.value)))) : null)));
229
+ layout?.secondaryTextExpression && !isAddNew ? (React.createElement(Typography, { sx: { marginLeft: '8px', fontSize: '14px', color: '#637381' } }, compileExpression(layout?.secondaryTextExpression, options.find((o) => o.id === option.value)))) : null)));
216
230
  }, onOpen: (e) => {
217
231
  // Don't open the options if there is a value that links to another page
218
232
  if (!(navigationSlug &&
219
233
  navigateTo &&
220
234
  ['DIV', 'INPUT'].includes(e.target?.nodeName) &&
221
- hasValue)) {
235
+ hasValue &&
236
+ (!('key' in e) || (e.key !== 'ArrowDown' && e.key !== 'ArrowUp')))) {
222
237
  setOpenOptions(true);
223
238
  }
224
239
  }, onClose: () => setOpenOptions(false), value: hasValue
@@ -239,6 +254,36 @@ export const ObjectPropertyInput = (props) => {
239
254
  return typeof option === 'string'
240
255
  ? (options.find((o) => o.id === option)?.name ?? '')
241
256
  : option.label;
257
+ }, ListboxProps: {
258
+ ref: listboxRef,
259
+ }, onHighlightChange: (e, option) => {
260
+ if (!option || !e || !('key' in e) || !listboxRef.current)
261
+ return;
262
+ const highlightedIndex = dropdownOptions.findIndex((opt) => opt.value === option.value);
263
+ // Only handle regular options (not the "Add New" button)
264
+ if (highlightedIndex >= options.length)
265
+ return;
266
+ const listbox = listboxRef.current;
267
+ const items = listbox.querySelectorAll('li');
268
+ const highlightedElement = items[highlightedIndex];
269
+ const addNewButton = mode !== 'existingOnly' &&
270
+ relatedObject?.actions?.some((a) => a.id === DEFAULT_CREATE_ACTION)
271
+ ? items[items.length - 1]
272
+ : undefined;
273
+ if (!highlightedElement || !addNewButton)
274
+ return;
275
+ const buttonHeight = addNewButton.offsetHeight;
276
+ const elementTop = highlightedElement.offsetTop;
277
+ const elementHeight = highlightedElement.offsetHeight;
278
+ const listboxScrollTop = listbox.scrollTop;
279
+ const listboxHeight = listbox.clientHeight;
280
+ // Check if element is hidden below the sticky button
281
+ const elementBottom = elementTop + elementHeight;
282
+ const visibleBottom = listboxScrollTop + listboxHeight - buttonHeight;
283
+ if (elementBottom > visibleBottom) {
284
+ // Scroll just enough to show the element above the sticky button
285
+ listbox.scrollTop = elementBottom - listboxHeight + buttonHeight;
286
+ }
242
287
  }, onKeyDown: (e) => {
243
288
  // prevents keyboard trap
244
289
  if (e.key === 'Tab') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.9.0-dev.0",
3
+ "version": "1.9.0-dev.1",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",