Skip to content

Commit d592bfb

Browse files
committed
remove the "empty" property exposed on the Select.tsx component's forwarded ref (redundant/extraneous) - breaking change
1 parent cd88905 commit d592bfb

File tree

7 files changed

+24
-38
lines changed

7 files changed

+24
-38
lines changed

__stories__/helpers/components/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const CHECK_BORDER_COLOR = hexToRgba(CHECK_COLOR, 0.83);
1414

1515
const Label = styled.span`
1616
user-select: none;
17-
margin-left: 1.45rem;
17+
margin-left: 1.4rem;
1818
`;
1919

2020
const Input = styled.input`

__stories__/helpers/constants/markup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const CLASS_NAME_HTML =
2323
type="text"
2424
class="${AUTOSIZE_INPUT_CLS}"
2525
/>
26+
::after
2627
</div>
2728
</div>
2829
<div>

__stories__/helpers/styled/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export const CardBody = styled.div<{ multiComponents?: boolean }>`
291291
multiComponents &&
292292
css`
293293
> div {
294-
margin-bottom: 1.5rem;
294+
margin-bottom: 3rem;
295295
296296
:first-of-type > label {
297297
margin-top: 0;
@@ -350,8 +350,8 @@ const SPIN_KEYFRAMES = keyframes`
350350
const SPIN_ANIMATION_CSS = css`animation: ${SPIN_KEYFRAMES} infinite 8s linear;`;
351351

352352
export const ReactSvg = styled.svg<{ isDisabled?: boolean }>`
353-
width: 32px;
354-
height: 32px;
353+
width: 30px;
354+
height: 30px;
355355
color: #1ea7fd;
356356
fill: currentColor;
357357
display: inline-block;

__stories__/index.stories.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ export const Methods = () => {
552552
<Title>Methods {'&'} Properties</Title>
553553
<Hr />
554554
<ListWrapper>
555-
<strong>5</strong> methods and <strong>2</strong> properties are exposed
556-
to wrapping components and are accessible via a forwarded <code>ref</code>.
555+
<strong>5</strong> methods and <strong>1</strong> property are exposed to
556+
wrapping components and are accessible via a forwarded <code>ref</code>.
557557
<List>
558558
<Li>
559559
<TextHeader>blur() {'=>'} void</TextHeader> - blur the control
@@ -575,12 +575,8 @@ export const Methods = () => {
575575
<TextHeader>setValue(option?: any) {'=>'} void</TextHeader> - set the
576576
value programatically <em>(option will be validated)</em>
577577
</Li>
578-
<Hr />
579578
<Li>
580-
<TextHeader>empty: boolean</TextHeader> - Whether the select has a value
581-
</Li>
582-
<Li>
583-
<TextHeader>menuOpen: boolean</TextHeader> - Whether or not the menu is open
579+
<TextHeader>menuOpen: boolean</TextHeader> - Open state of the menu
584580
</Li>
585581
</List>
586582
</ListWrapper>
@@ -703,11 +699,10 @@ export const Filtering = () => {
703699
};
704700

705701
export const Virtualization = () => {
702+
const optionCountList = useMemo<number[]>(() => [100, 1000, 10000, 25000, 50000, 100000], []);
706703
const selectRef = useRef<SelectRef | null>(null);
707704
const [options, setOptions] = useState<Option[]>([]);
708-
const [optionsCount, setOptionsCount] = useState(100);
709-
710-
const optionCountList = [100, 1000, 10000, 25000, 50000, 100000];
705+
const [optionsCount, setOptionsCount] = useState(optionCountList[0]);
711706

712707
useUpdateEffect(() => {
713708
selectRef.current?.clearValue();
@@ -767,7 +762,7 @@ export const Virtualization = () => {
767762
<Hr />
768763
<Card>
769764
<CardHeader>
770-
<Label>Number of Options</Label>
765+
<Label>Options Count</Label>
771766
<Buttons>
772767
{optionCountList.map((count) => (
773768
<OptionsCountButton

src/Select.tsx

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ const Select = forwardRef<SelectRef, SelectProps>((
380380
useImperativeHandle(
381381
ref,
382382
() => ({
383-
empty: !hasSelectedOptions,
384383
menuOpen: menuOpenRef.current,
385384
blur: blurInput,
386385
focus: focusInput,
@@ -401,7 +400,7 @@ const Select = forwardRef<SelectRef, SelectProps>((
401400
}
402401
}
403402
}),
404-
[hasSelectedOptions, getOptionValueFn, getOptionLabelFn, openMenuAndFocusOption]
403+
[getOptionValueFn, getOptionLabelFn, openMenuAndFocusOption]
405404
);
406405

407406
/**
@@ -412,16 +411,6 @@ const Select = forwardRef<SelectRef, SelectProps>((
412411
autoFocus && focusInput();
413412
});
414413

415-
/**
416-
* useEffect
417-
* If control recieves focus & openMenuOnFocus = true, open menu
418-
*/
419-
useEffect(() => {
420-
if (isFocused && openMenuOnFocus) {
421-
openMenuAndFocusOption(OptionIndexEnum.FIRST);
422-
}
423-
}, [isFocused, openMenuOnFocus, openMenuAndFocusOption]);
424-
425414
/**
426415
* useEffect
427416
* If 'onSearchChange' function is defined, run as callback when the stateful debouncedInputValue
@@ -653,18 +642,21 @@ const Select = forwardRef<SelectRef, SelectProps>((
653642
if (isNotInput) e.preventDefault();
654643
};
655644

656-
const handleOnInputFocus = (e: FocusEvent<HTMLInputElement>): void => {
657-
onInputFocus?.(e);
658-
setIsFocused(true);
659-
};
660-
661645
const handleOnInputBlur = (e: FocusEvent<HTMLInputElement>): void => {
662646
onInputBlur?.(e);
663647
setIsFocused(false);
664648
setMenuOpen(false);
665649
setInputValue('');
666650
};
667651

652+
const handleOnInputFocus = (e: FocusEvent<HTMLInputElement>): void => {
653+
onInputFocus?.(e);
654+
setIsFocused(true);
655+
if (openMenuOnFocus) {
656+
openMenuAndFocusOption(OptionIndexEnum.FIRST);
657+
}
658+
};
659+
668660
const handleOnInputChange = (e: FormEvent<HTMLInputElement>): void => {
669661
onChangeEvtValue.current = true;
670662
onInputChange?.(e.currentTarget.value);
@@ -683,10 +675,9 @@ const Select = forwardRef<SelectRef, SelectProps>((
683675
}, []);
684676

685677
const handleOnCaretMouseDown = useCallback((e: MouseOrTouchEvent<HTMLElement>): void => {
686-
if (!isDisabled && !openMenuOnClick) {
687-
handleOnMouseDown(e);
688-
menuOpenRef.current ? setMenuOpen(false) : openMenuAndFocusOption(OptionIndexEnum.FIRST);
689-
}
678+
if (isDisabled || openMenuOnClick) return;
679+
handleOnMouseDown(e);
680+
menuOpenRef.current ? setMenuOpen(false) : openMenuAndFocusOption(OptionIndexEnum.FIRST);
690681
}, [isDisabled, openMenuOnClick, openMenuAndFocusOption]);
691682

692683
const showClear = !!isClearable && !isDisabled && hasSelectedOptions;

src/components/AutosizeInput/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const InputWrapper = styled.div`
4545
}
4646
`;
4747

48-
const Input = styled.input.attrs(AUTOSIZE_INPUT_ATTRS) <InputProps>`
48+
const Input = styled.input.attrs(AUTOSIZE_INPUT_ATTRS)<InputProps>`
4949
width: 100%;
5050
background: 0;
5151
color: inherit;

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export type MenuOption = Readonly<{
6060
}>;
6161

6262
export type SelectRef = Readonly<{
63-
empty: boolean;
6463
menuOpen: boolean;
6564
blur: () => void;
6665
focus: () => void;

0 commit comments

Comments
 (0)