@redocly/theme 0.52.0-next.3 → 0.52.0-next.4

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.
Files changed (37) hide show
  1. package/lib/components/Button/Button.d.ts +1 -0
  2. package/lib/components/Button/Button.js +2 -1
  3. package/lib/components/Dropdown/Dropdown.js +1 -1
  4. package/lib/components/Link/Link.js +2 -2
  5. package/lib/components/Search/FilterFields/SearchFilterFieldTags.js +12 -5
  6. package/lib/components/Search/SearchDialog.js +78 -27
  7. package/lib/components/Search/SearchInput.d.ts +2 -2
  8. package/lib/components/Search/SearchInput.js +4 -4
  9. package/lib/components/Search/SearchItem.d.ts +3 -1
  10. package/lib/components/Search/SearchItem.js +53 -28
  11. package/lib/components/Search/variables.js +0 -1
  12. package/lib/components/Select/Select.js +6 -3
  13. package/lib/components/Select/SelectInput.d.ts +1 -0
  14. package/lib/components/Select/SelectInput.js +13 -2
  15. package/lib/components/Tag/Tag.d.ts +3 -1
  16. package/lib/components/Tag/Tag.js +2 -2
  17. package/lib/components/UserMenu/UserMenu.js +1 -1
  18. package/lib/core/hooks/menu/use-collapse.js +0 -1
  19. package/lib/core/hooks/use-dialog-hotkeys.js +1 -2
  20. package/lib/icons/ReturnKeyIcon/ReturnKeyIcon.d.ts +3 -0
  21. package/lib/icons/ReturnKeyIcon/ReturnKeyIcon.js +18 -0
  22. package/package.json +2 -2
  23. package/src/components/Button/Button.tsx +4 -1
  24. package/src/components/Dropdown/Dropdown.tsx +0 -1
  25. package/src/components/Link/Link.tsx +2 -1
  26. package/src/components/Search/FilterFields/SearchFilterFieldTags.tsx +13 -4
  27. package/src/components/Search/SearchDialog.tsx +126 -52
  28. package/src/components/Search/SearchInput.tsx +10 -3
  29. package/src/components/Search/SearchItem.tsx +89 -55
  30. package/src/components/Search/variables.ts +0 -1
  31. package/src/components/Select/Select.tsx +7 -2
  32. package/src/components/Select/SelectInput.tsx +14 -2
  33. package/src/components/Tag/Tag.tsx +6 -0
  34. package/src/components/UserMenu/UserMenu.tsx +1 -1
  35. package/src/core/hooks/menu/use-collapse.ts +0 -1
  36. package/src/core/hooks/use-dialog-hotkeys.ts +1 -1
  37. package/src/icons/ReturnKeyIcon/ReturnKeyIcon.tsx +13 -0
@@ -53,6 +53,7 @@ export function Select<T>(props: SelectProps<T>): JSX.Element {
53
53
  getSelectedOptionsFromPropsValue(),
54
54
  );
55
55
  const selectRef = useRef<HTMLDivElement | null>(null);
56
+ const selectInputRef = useRef<HTMLInputElement | null>(null);
56
57
  const [searchValue, setSearchValue] = useState<string | null>(null);
57
58
  const [dropdownActive, setDropdownActive] = useState<boolean | undefined>(false);
58
59
  const [filteredOptions, setFilteredOptions] = useState<SelectOption<T>[]>(options);
@@ -110,9 +111,12 @@ export function Select<T>(props: SelectProps<T>): JSX.Element {
110
111
  onChange?.(newSelectedValues);
111
112
  setSearchValue(null);
112
113
  setDropdownActive(false);
114
+
113
115
  if (!multiple) {
114
116
  setStickyInputValue('');
115
117
  }
118
+
119
+ selectInputRef.current?.focus();
116
120
  };
117
121
 
118
122
  const searchHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -163,7 +167,7 @@ export function Select<T>(props: SelectProps<T>): JSX.Element {
163
167
  );
164
168
  };
165
169
 
166
- const renderDefaultInput = () => {
170
+ const renderDefaultInput = (inputRef: React.ForwardedRef<HTMLInputElement>) => {
167
171
  return (
168
172
  <SelectInput
169
173
  id={inputId}
@@ -175,6 +179,7 @@ export function Select<T>(props: SelectProps<T>): JSX.Element {
175
179
  searchable={searchable}
176
180
  clearable={clearable}
177
181
  customIcon={icon}
182
+ inputRef={inputRef}
178
183
  onlyIcon={onlyIcon}
179
184
  clearHandler={clearHandler}
180
185
  searchHandler={searchHandler}
@@ -197,7 +202,7 @@ export function Select<T>(props: SelectProps<T>): JSX.Element {
197
202
  <SelectDropdown
198
203
  closeOnClick={!multiple}
199
204
  withArrow={withArrow}
200
- trigger={renderInput ? renderInput() : renderDefaultInput()}
205
+ trigger={renderInput ? renderInput() : renderDefaultInput(selectInputRef)}
201
206
  triggerEvent={triggerEvent}
202
207
  placement={placement}
203
208
  alignment={alignment}
@@ -19,6 +19,7 @@ type SelectInputProps<T> = {
19
19
  multiple?: boolean;
20
20
  searchable?: boolean;
21
21
  clearable?: boolean;
22
+ inputRef?: React.ForwardedRef<HTMLInputElement>;
22
23
  clearHandler?: (value?: any) => void;
23
24
  inputBlurHandler?: (e?: any) => void;
24
25
  inputFocusHandler?: (e?: any) => void;
@@ -53,7 +54,6 @@ export function SelectInput<T>(props: SelectInputProps<T>): React.ReactNode {
53
54
  };
54
55
 
55
56
  const onKeyDownHandler = (e: any) => {
56
- e.stopPropagation();
57
57
  if (e.key === 'Backspace' && !searchValue && selectedOptions.length) {
58
58
  clearHandler?.(selectedOptions[selectedOptions.length - 1]);
59
59
  inputRef.current?.focus();
@@ -105,7 +105,19 @@ export function SelectInput<T>(props: SelectInputProps<T>): React.ReactNode {
105
105
  onChange={onChangeHandler}
106
106
  onKeyDown={onKeyDownHandler}
107
107
  onBlur={onBlurHandler}
108
- ref={inputRef}
108
+ ref={(input) => {
109
+ if (!input) return;
110
+
111
+ inputRef.current = input;
112
+
113
+ if (!props.inputRef) return;
114
+
115
+ if (typeof props.inputRef === 'function') {
116
+ props.inputRef(input);
117
+ } else {
118
+ props.inputRef.current = input;
119
+ }
120
+ }}
109
121
  width={multiple ? (!searchValue && selectedOptions.length ? '10px' : 'auto') : '100%'}
110
122
  />
111
123
  );
@@ -39,7 +39,9 @@ export type TagProps = {
39
39
  size?: string;
40
40
  icon?: React.ReactNode;
41
41
  active?: boolean;
42
+ tabIndex?: number;
42
43
  onClick?: (event: React.MouseEvent) => void;
44
+ onKeyDown?: (event: React.KeyboardEvent) => void;
43
45
  onClose?: (event: React.MouseEvent) => void;
44
46
  };
45
47
 
@@ -49,7 +51,9 @@ export function Tag({
49
51
  icon,
50
52
  active,
51
53
  closable,
54
+ tabIndex,
52
55
  onClick,
56
+ onKeyDown,
53
57
  onClose,
54
58
  size,
55
59
  borderless,
@@ -59,11 +63,13 @@ export function Tag({
59
63
  }: TagProps): JSX.Element {
60
64
  return (
61
65
  <TagWrapper
66
+ tabIndex={tabIndex}
62
67
  data-component-name="Tag/Tag"
63
68
  borderless={borderless}
64
69
  color={color}
65
70
  size={size}
66
71
  onClick={onClick}
72
+ onKeyDown={onKeyDown}
67
73
  hasCloseButton={closable}
68
74
  {...otherProps}
69
75
  >
@@ -65,7 +65,7 @@ export function UserMenu({ className }: UserMenuProps) {
65
65
  className={className}
66
66
  alignment="end"
67
67
  trigger={
68
- <UserMenuTrigger role="button">
68
+ <UserMenuTrigger role="button" tabIndex={0}>
69
69
  <UserAvatar picture={userData.picture} />
70
70
  </UserMenuTrigger>
71
71
  }
@@ -207,6 +207,5 @@ export function useEvent<T extends (...args: any[]) => any>(callback?: T) {
207
207
  ref.current = callback;
208
208
  });
209
209
 
210
- // eslint-disable-next-line react-hooks/exhaustive-deps
211
210
  return useCallback(((...args: any) => ref.current?.(...args)) as T, []);
212
211
  }
@@ -30,12 +30,12 @@ export function useDialogHotKeys(
30
30
  if (focusableElements && focusableElements.length > 0) {
31
31
  firstFocusableRef.current = focusableElements[0] as HTMLElement;
32
32
  lastFocusableRef.current = focusableElements[focusableElements.length - 1] as HTMLElement;
33
- firstFocusableRef.current?.focus();
34
33
  }
35
34
  };
36
35
 
37
36
  useEffect(() => {
38
37
  document.addEventListener('keydown', onKeyDownHandler);
38
+
39
39
  return () => {
40
40
  document.removeEventListener('keydown', onKeyDownHandler);
41
41
  };
@@ -0,0 +1,13 @@
1
+ import styled from 'styled-components';
2
+
3
+ import { Typography } from '@redocly/theme/components/Typography/Typography';
4
+
5
+ export const ReturnKeyIcon = styled(Typography).attrs(() => ({
6
+ 'data-component-name': 'icons/ReturnKeyIcon/ReturnKeyIcon',
7
+ }))`
8
+ margin-left: auto;
9
+
10
+ ::after {
11
+ content: '⏎';
12
+ }
13
+ `;