-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(select): Create a generic Id type for Option interface #214
Conversation
- Add title as an interface prop and set type as ReactNode - Create an enum for Language options and use it in Select and TypeaheadSelect components
|
src/select/util/selectTypes.ts
Outdated
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface TypeaheadSelectOption extends Option {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use type instead of an interface to avoid disabling this rule.
// eslint-disable-next-line @typescript-eslint/no-empty-interface | |
interface TypeaheadSelectOption extends Option {} | |
type TypeaheadSelectOption = Option; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the way you said, but it didn't let me set a generic type to TypeaheadSelectOption
🤔
src/select/util/selectTypes.ts
Outdated
id: string; | ||
interface Option<Id = string> { | ||
id: Id; | ||
title: React.ReactNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we add title
property here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be useful for some cases, but I can set it as optional or remove it completely.
- Use contentRenderer as Select.Item content - Use contentRenderer for tag content as we removed the title prop - Instead of handling the keyword change inside TypeaheadSelect by filtering titles, handle it outside of the component
…d to set initial and changeable value - Set canSelectMultiple to false if options.length is not bigger than 1 - Add testid to use in typeahead-select.test - Add onClick optional prop to TypeheadSelectTrigger to set the correct classname when the menu is open - setMenuVisibility to false if shouldCloseOnSelect is true, so that the classnames are correct - Remove input styles when TypeaheadSelectInput is used inside of the trigger - Add testid to TypeheadSelectTrigger to test it easily - Fix most of the test cases for typeahead-select - Fix classnames - I used screen.findByText function to find the option but I can update it Note:- In my opinion, having two classnames for typeahead-select and select is a bit unnecessary. We can just add typeahead-select as main classname and override select classnames if necessary. - I couldn't fix a11y test case for the typeahead-select.
@@ -47,6 +47,7 @@ function SelectComponent<T extends Option = Option>( | |||
return ( | |||
<div | |||
ref={selectRef} | |||
data-testid={props.testid} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the ideal scenario, I think we should be able to get all "div" props in addition to the SelectProps
and pass all of them to the div element. But it is fine for now. Maybe we can discuss it later on and use this logic on other components as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have made a refactor for that component. It looks too complex :(
<Select.Trigger customClassName={"typeahead-select-trigger"}> | ||
<Select.Trigger | ||
customClassName={"typeahead-select-trigger"} | ||
testid={"TypeaheadSelectTrigger"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this testid?
…d as we usually handle the state of the keyword outside of the component
title
fromTypeaheadSelectOption
and usecontentRenderer
prop as children toSelect.Item
inTypeaheadSelect
Select
andTypeaheadSelect
componentscontentRenderer
fortag
content as we removed thetitle
propinitialKeyword
and usecontrolledKeyword
to set initial and changeable valuecanSelectMultiple
to false ifoptions.length
is not bigger than 1testid
to use intypeahead-select.test
onClick
optional prop toTypeheadSelectTrigger
to set the correctclassname
when the menu is opensetMenuVisibility
to false ifshouldCloseOnSelect
is true, so that theclassnames
are correctTypeaheadSelectInput
is used inside of the triggertestid
toTypeheadSelectTrigger
to test it easilytypeahead-select
- Fix classnames
- I used
screen.findByText
function to find the option but I can update itNote:
TypeaheadSelect
and Select is a bit unnecessary. We can just add typeahead-select as main classname and override select classnames if necessary.a11y
test case for thetypeahead-select
.Id
as generic type