Skip to content

Commit

Permalink
fix: Clean up useselectinput
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel.carrera committed Sep 6, 2023
1 parent 9311d96 commit 1b24e52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
5 changes: 2 additions & 3 deletions modules/react/select/lib/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ export const SelectInput = createSubcomponent(TextInput)({
modelHook: useSelectModel,
elemPropsHook: useSelectInput,
})<SelectInputProps>(
({placeholder = 'Choose an Option', width, inputStartIcon, ...props}, Element, model) => {
({placeholder = 'Choose an Option', inputStartIcon, ...props}, Element, model) => {
return (
<InputGroup width={width}>
<InputGroup>
{inputStartIcon && model.state.selectedIds.length > 0 && (
<InputGroup.InnerStart pointerEvents="none">
<SystemIcon icon={inputStartIcon} />
</InputGroup.InnerStart>
)}
<InputGroup.Input
width={width}
as={Element}
placeholder={placeholder}
style={{caretColor: 'transparent', cursor: 'default'}}
Expand Down
7 changes: 1 addition & 6 deletions modules/react/select/lib/hooks/useSelectInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ export const useSelectInput = composeHooks(
keysToOpenSelect.includes(event.key) ||
(event.key === ' ' && model.state.visibility === 'hidden' && keySofar.current === '')
) {
// set the width of the popup when the select is triggered to open by a specified key
model.events.setWidth(event.currentTarget.clientWidth);
//show the menu when enter is typed
model.events.show();
}
Expand All @@ -140,7 +138,7 @@ export const useSelectInput = composeHooks(
if (model.state.visibility === 'hidden') {
model.events.goTo({id: model.state.items[foundIndex].id});

if (model.state.isVirtualized && model.state.selectedIds.length > 0) {
if (model.state.selectedIds.length > 0) {
model.state.UNSTABLE_virtual.scrollToIndex(foundIndex);
}
}
Expand Down Expand Up @@ -190,9 +188,6 @@ export const useSelectInput = composeHooks(
},

onClick(event: React.MouseEvent) {
if (model.state.visibility === 'hidden') {
model.events.setWidth(event.currentTarget.clientWidth);
}
// When you click the menu and there's a selected item
// scroll to that selected item
if (model.state.selectedIds.length > 0) {
Expand Down

0 comments on commit 1b24e52

Please sign in to comment.