Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

gulcinuras
Copy link
Contributor

@gulcinuras gulcinuras commented Nov 28, 2022

  • Remove title from TypeaheadSelectOption and use contentRenderer prop as children to Select.Item in TypeaheadSelect
  • Create an enum for Language options and use it in Select and TypeaheadSelect components
  • Use contentRenderer for tag content as we removed the title prop
  • Remove initialKeyword and use controlledKeyword 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 similar classnames for TypeaheadSelect 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.
  • As indicated in Select: Type improvements #206 issue I added Id as generic type

- 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
@github-actions
Copy link

github-actions bot commented Nov 28, 2022

PR Preview Action v1.4.7
Preview removed because the pull request was closed.
2024-04-01 11:07 UTC

Comment on lines 15 to 16
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface TypeaheadSelectOption extends Option {}
Copy link
Contributor

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.

Suggested change
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface TypeaheadSelectOption extends Option {}
type TypeaheadSelectOption = Option;

Copy link
Contributor Author

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 🤔

@gulcinuras gulcinuras linked an issue Nov 28, 2022 that may be closed by this pull request
id: string;
interface Option<Id = string> {
id: Id;
title: React.ReactNode;
Copy link
Contributor

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?

Copy link
Contributor Author

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
@gulcinuras gulcinuras requested a review from Anlerkan January 10, 2023 18:11
ErenYLCN
ErenYLCN previously approved these changes Jan 23, 2023
@ErenYLCN ErenYLCN added the bug Something isn't working label Jan 23, 2023
@gulcinuras gulcinuras added W.I.P Work in progress and removed bug Something isn't working ready for review labels Jan 23, 2023
…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.
@gulcinuras gulcinuras added ready for review and removed W.I.P Work in progress labels Jan 24, 2023
@gulcinuras gulcinuras requested a review from ErenYLCN January 24, 2023 21:35
@Anlerkan Anlerkan changed the base branch from main to next-release January 27, 2023 18:38
@Anlerkan Anlerkan dismissed ErenYLCN’s stale review January 27, 2023 18:38

The base branch was changed.

@gulcinuras gulcinuras requested review from mucahit, yigiterdev and a team February 9, 2023 15:38
@@ -47,6 +47,7 @@ function SelectComponent<T extends Option = Option>(
return (
<div
ref={selectRef}
data-testid={props.testid}
Copy link
Contributor

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

Copy link
Contributor

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"}
Copy link
Contributor

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?

@gulcinuras gulcinuras closed this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Select: Type improvements
6 participants