-
Notifications
You must be signed in to change notification settings - Fork 31
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
Conversation
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.
This seems fine to me. Asking for @chrispulsinelli-okta for some help getting an approval for this
[errorMessage, hint, isOptional, label, nameOverride] | ||
[ | ||
errorMessage, | ||
errorMessageList, |
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.
lint fix here @bryancunningham-okta @chrispulsinelli-okta
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'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"; |
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.
Any reason why you removed FC
as an imported object? I believe this affects the interface definition below where it extends FC
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 believe this should be something like import React, { FC } from "react";
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.
@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
You have the following errors in the build:
|
@chrispulsinelli-okta I didn't touch the UPDATE: This build error actually did result from changes to |
7c50d3d
d8a3bdc
to
f954b6c
Compare
id={idOverride} | ||
inputProps={{ | ||
"aria-errormessage": errorMessageElementId, | ||
"aria-labelledby": labelElementId, | ||
"data-se": 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.
id={id} | ||
inputProps={{ "data-se": 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.
type DataAttributeKey = `data-${string}`; | ||
declare module "react" { | ||
interface InputHTMLAttributes<T> extends HTMLAttributes<T> { |
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 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 |
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.
Nice documentation comment! 👍
defaultValue, | ||
errorMessage, | ||
errorMessageList, | ||
hasMultipleChoices: hasMultipleChoicesProp, | ||
hint, | ||
HintLinkComponent, | ||
id: idOverride, | ||
inputFocusRef, |
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'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(); |
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'd like to have this match other places in the code:
element && element.focus(); | |
element?.focus(); |
useImperativeHandle( | ||
inputFocusRef, | ||
() => { | ||
const element = inputRef.current; |
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 don't think we need to create this element
variable.
I'm fine having inputRef.current?.focus()
below.
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.
A few comments, but it's otherwise very close! :)
Summary
testId
had placed it on the wrapper MUI element for all MUI components that wrap an underlying raw HTMLinput
element (e.g.TextField
,Checkbox
,Radio
, etc.). Most downstream repos have written their unit and e2e tests expecting that thedata-se
attribute is on the raw HTMLinput
element rather than a wrapper parent element, so this PR movesdata-se
to MUI'sinputProps
HTMLAttributes
to allowdata-*
attributes because of an underlying issue with TypeScriptFocusHandle
out of declaration file because it fits better ininputUtils.ts
NativeSelect