@thecb/components 6.0.0-beta.28 → 6.0.0-beta.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "6.0.0-beta.28",
3
+ "version": "6.0.0-beta.30",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -107,6 +107,7 @@ const Dropdown = ({
107
107
  const [selectedRef, setSelectedRef] = useState(undefined);
108
108
  const [focusedRef, setFocusedRef] = useState(undefined);
109
109
  const [inputChangedByAutofill, setInputChangedByAutofill] = useState(false);
110
+ const [focusedByClick, setFocusedByClick] = useState(false);
110
111
 
111
112
  if (optionsState !== options) {
112
113
  setOptionsState(options);
@@ -206,14 +207,22 @@ const Dropdown = ({
206
207
  };
207
208
 
208
209
  useEffect(() => {
209
- if (isOpen && selectedRef !== undefined && selectedRef.current !== null) {
210
+ const selectedRefExists =
211
+ selectedRef !== undefined && selectedRef.current !== null;
212
+ if (isOpen && selectedRefExists && !focusedByClick) {
210
213
  // WAI-ARIA requires the selected option to receive focus
211
214
  selectedRef.current.focus();
212
- console.log("input box ref", inputRef, inputRef.current);
213
- } else if (isOpen && optionRefs.current[0].current) {
215
+ } else if (isOpen && optionRefs.current[0].current && !focusedByClick) {
214
216
  // If no selected option, first option receives focus
215
217
  optionRefs.current[0].current.focus();
216
- console.log("input box ref", inputRef, inputRef.current);
218
+ }
219
+ if (isOpen && focusedByClick && selectedRefExists) {
220
+ selectedRef.current.scrollIntoView({
221
+ behavior: "smooth",
222
+ block: "nearest",
223
+ inline: "start"
224
+ });
225
+ setFocusedByClick(false);
217
226
  }
218
227
  clearTimeout(timer);
219
228
  setInputValue("");
@@ -266,6 +275,7 @@ const Dropdown = ({
266
275
  minWidth="100%"
267
276
  onClick={() => {
268
277
  if (!isOpen) {
278
+ setFocusedByClick(true);
269
279
  onClick();
270
280
  }
271
281
  }}