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: move testId to inputProps for all input components #2096

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

trevoring-okta
Copy link
Contributor

@trevoring-okta trevoring-okta commented Jan 22, 2024

Summary

  • Existing implementation of testId had placed it on the wrapper MUI element for all MUI components that wrap an underlying raw HTML input element (e.g. TextField, Checkbox, Radio, etc.). Most downstream repos have written their unit and e2e tests expecting that the data-se attribute is on the raw HTML input element rather than a wrapper parent element, so this PR moves data-se to MUI's inputProps
    • Required module augmentation of React's HTMLAttributes to allow data-* attributes because of an underlying issue with TypeScript
    • Moved FocusHandle out of declaration file because it fits better in inputUtils.ts
    • Fixes missing input focus ref and autocomplete props from NativeSelect

Copy link
Contributor

@bryancunningham-okta bryancunningham-okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me. Asking for @chrispulsinelli-okta for some help getting an approval for this

[errorMessage, hint, isOptional, label, nameOverride]
[
errorMessage,
errorMessageList,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@chrispulsinelli-okta chrispulsinelli-okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this change and leaving an approval as to not block you, but please review and update, if necessary, the change to the import statement in react-augment.d.ts please. Once that is addressed, this should be fine to merge.

@@ -10,14 +10,18 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

import { FC } from "react";

import "react";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you removed FC as an imported object? I believe this affects the interface definition below where it extends FC

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be something like import React, { FC } from "react";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrispulsinelli-okta So this change to react-augment.d.ts came from a discussion with Kevin. I saw that you were the original author of this file but Kevin was saying he thought the ForwardRefWithType definition would actually fit better in inputUtils.ts (just like what I did with FocusHandle) since d.ts files shouldn't be used for holding custom types. I'm not a TS expert so I'm most relaying what Kevin was saying, but he originally wanted me to move your ForwardRefWithType interface into inputUtils.ts in this ticket as well but it led to a bunch of TS compiler errors when I tried to do so since Odyssey has "skipLibCheck": true in tsconfig which prevents type checking in d.ts files.

I don't have any context behind ForwardRefWithType and didn't want to break your code so Kevin asked me to create a ticket and assign it to you for this sprint: https://oktainc.atlassian.net/browse/OKTA-688308

Regardless, I can still add back the FC for the scope of this PR

@chrispulsinelli-okta
Copy link
Contributor

You have the following errors in the build:

Error: src/labs/DatePicker.tsx(21,10): error TS2590: Expression produces a union type that is too complex to represent.
lerna ERR! yarn run typecheck exited 2 in '@okta/odyssey-react-mui'

@trevoring-okta
Copy link
Contributor Author

trevoring-okta commented Jan 25, 2024

You have the following errors in the build:

Error: src/labs/DatePicker.tsx(21,10): error TS2590: Expression produces a union type that is too complex to represent.
lerna ERR! yarn run typecheck exited 2 in '@okta/odyssey-react-mui'

@chrispulsinelli-okta I didn't touch the DatePicker component as part of this PR but I can still try to resolve the issue. Do you anticipate this blocking the publishing of this PR if it doesn't get resolved?

UPDATE: This build error actually did result from changes to react-augment.d.ts, they have been fixed

id={idOverride}
inputProps={{
"aria-errormessage": errorMessageElementId,
"aria-labelledby": labelElementId,
"data-se": testId,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id={id}
inputProps={{ "data-se": testId }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 20 to 22
type DataAttributeKey = `data-${string}`;
declare module "react" {
interface InputHTMLAttributes<T> extends HTMLAttributes<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will approve, but please check if the type definition at line 20 is supposed to go inside the declare at line 21.

I didn't notice it before, but I'm thinking that's how you localize global type overrides.

/**
* This prop helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, as it's more like an autofill.
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice documentation comment! 👍

defaultValue,
errorMessage,
errorMessageList,
hasMultipleChoices: hasMultipleChoicesProp,
hint,
HintLinkComponent,
id: idOverride,
inputFocusRef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like this to be more generic.

Can we rename this inputRef so maybe .blur() is possible in the future and others?

The internal one could be named localInputRef to differentiate it.

const element = inputRef.current;
return {
focus: () => {
element && element.focus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have this match other places in the code:

Suggested change
element && element.focus();
element?.focus();

useImperativeHandle(
inputFocusRef,
() => {
const element = inputRef.current;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to create this element variable.

I'm fine having inputRef.current?.focus() below.

Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, but it's otherwise very close! :)

@trevoring-okta trevoring-okta merged commit 94ec2ea into main Jan 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants