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: pulled out TextField into separate components #1744

Merged
merged 8 commits into from
Apr 14, 2023

Conversation

KevinGhadyani-Okta
Copy link
Contributor

@KevinGhadyani-Okta KevinGhadyani-Okta commented Apr 10, 2023

Description

This PR is a precursor to unblocking Autocomplete. Autocomplete requires a render function, and this needs to return a React component. Our TextField doesn't support all props needed by it, so we need to gut it and let Autocomplete build its own input using those guts.

As part of this PR:

  • TextField's innards have been moved to Field since they're shared by numerous components.
  • Created PasswordField and SearchField as there's already a task to split these out.
  • Wrapping RadioGroup and CheckboxGroup is coming in a future task as they share this API.
  • Documentation was minimal. That's coming in a future task.


import { memo } from "react";

import { FormHelperText, visuallyHidden } from ".";
Copy link
Contributor

Choose a reason for hiding this comment

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

Importing from "." (or index.ts, which is probably a re-export) is not recommended, especially since this is in the same folder so it is not subject to portability rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll change these in a future PR. I'll add a ticket for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KevinGhadyani-Okta KevinGhadyani-Okta force-pushed the kg/OKTA-596518 branch 5 times, most recently from 975a463 to 5f34a13 Compare April 11, 2023 19:37

const Field = ({
errorMessage,
hasVisibleLabel,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably default to true -- nearly all fields should have a visible label

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine. It's on Field though where we're being explicit. It's internal-only. TextField, SearchField, etc won't be exposing this.

return (
<Field
errorMessage={errorMessage}
hasVisibleLabel
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be optional if we have it default to true? Not strongly opinionated there, since we want visible labels as a standard.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is like hint and error. We're defining what we want on Field. Only 6-7 components will use it. Even if we expose it, this is all for dev maintenance. Someone can look at it and know what to expect. Rather than telling them to turn off a feature, they're telling this component what they want to show up.

const FieldError = ({ id, text }: FieldErrorProps) => {
return (
<FormHelperText error id={id}>
<span style={visuallyHidden}>Error: </span>
Copy link
Contributor

Choose a reason for hiding this comment

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

These should use ScreenReaderText now that it's available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FieldLabel does not.

It's a bit more complex:

InputLabel
  htmlFor={inputId}
  id={id}
  style={hasVisibleLabel ? undefined : visuallyHidden}
>

I'd have to duplicate this. I guess I could useCallback or useMemo it. I'll fix that now.

Copy link
Contributor

@edburyenegren-okta edburyenegren-okta Apr 14, 2023

Choose a reason for hiding this comment

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

This change going in before merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be in now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KevinGhadyani-Okta KevinGhadyani-Okta merged commit 0b7a412 into develop Apr 14, 2023
@KevinGhadyani-Okta KevinGhadyani-Okta deleted the kg/OKTA-596518 branch April 14, 2023 18:40
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