-
Notifications
You must be signed in to change notification settings - Fork 86
feat(time): align Time with FE-7233 audit requirements #8052
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
Open
tamas-sage
wants to merge
11
commits into
master
Choose a base branch
from
feat/fe-7233-time-input-audit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3fd5149
feat(time): align Time with FE-7233 audit requirements
tamas-sage 938dbaa
test(time): fix FE-7233 coverage and CT accessibility checks
tamas-sage ee62321
test(time): fix lint no-node-access in FE-7233 coverage test
tamas-sage cec5a84
fix(time): apply audit feedback and token updates
tamas-sage 38dce17
test(time): cover next fieldset branches
tamas-sage c94f8fc
Merge branch 'master' into feat/fe-7233-time-input-audit
tamas-sage 9c72563
test(fieldset): cover width style branch
tamas-sage 3f9e186
Merge branch 'master' into feat/fe-7233-time-input-audit
tamas-sage 90d3027
test(time): address PR feedback and remove redundant style coverage
tamas-sage 7690843
fix(time): resolve lint error by default-exporting StyledColon
tamas-sage 6d6cf31
Merge branch 'master' into feat/fe-7233-time-input-audit
tamas-sage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ import useLocale from "../../hooks/__internal__/useLocale"; | |
| import tagComponent from "../../__internal__/utils/helpers/tags/tags"; | ||
| import { filterStyledSystemMarginProps } from "../../style/utils"; | ||
|
|
||
| import Fieldset from "../../__internal__/fieldset"; | ||
| import Fieldset from "../../__internal__/fieldset/__next__/fieldset.component"; | ||
| import Box from "../box"; | ||
| import Number from "../number"; | ||
| import Typography from "../typography"; | ||
| import StyledLabel from "./time.style"; | ||
| import Textbox from "../textbox"; | ||
| import Label from "../../__internal__/label"; | ||
| import StyledColon from "./time.style"; | ||
| import { TimeToggle, ToggleDataProps } from "./__internal__/time-toggle"; | ||
| import FieldsetValidationContext from "../../__internal__/fieldset-validation-context"; | ||
|
|
||
|
|
@@ -41,24 +41,28 @@ export interface TimeInputEvent { | |
| } | ||
|
|
||
| interface TimeInputProps extends TagProps, Omit<ValidationProps, "info"> { | ||
| /** Set an id value on the input */ | ||
| /** Set an id value on the input element */ | ||
| id?: string; | ||
| /** Override the default label text */ | ||
| /** Override the default label text on the input */ | ||
| label?: string; | ||
| /** Override the default aria-label text */ | ||
| /** Override the default aria-label text on the input */ | ||
| "aria-label"?: string; | ||
| } | ||
|
|
||
| export interface TimeProps extends TagProps, MarginProps { | ||
| /** Label text for the component */ | ||
| /** Legend text for the component */ | ||
| legend?: string; | ||
| /** Additional hint text rendered below the legend */ | ||
| legendHint?: string; | ||
| /** @deprecated Use `legend` instead. Label text for the component */ | ||
| label?: string; | ||
| /** Label alignment */ | ||
| /** @deprecated Alignment is no longer supported and this prop will be removed */ | ||
| labelAlign?: "left" | "right"; | ||
| /** Field labels alignment */ | ||
| /** @deprecated Alignment is no longer supported and this prop will be removed */ | ||
| fieldLabelsAlign?: "left" | "right"; | ||
| /** Sets the size of the inputs */ | ||
| size?: Sizes; | ||
| /** Additional hint text rendered above the input elements */ | ||
| /** @deprecated Use `legendHint` instead. Additional hint text rendered below the legend */ | ||
| inputHint?: string; | ||
| /** | ||
| * Set custom `data-` and `id` attributes on the input element. | ||
|
|
@@ -108,9 +112,9 @@ const SIZES = { | |
| const Time = React.forwardRef<TimeHandle, TimeProps>( | ||
| ( | ||
| { | ||
| legend, | ||
| legendHint, | ||
| label, | ||
| labelAlign, | ||
| fieldLabelsAlign, | ||
| size = "medium", | ||
| inputHint, | ||
| hoursInputProps = {}, | ||
|
|
@@ -131,14 +135,14 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| const { | ||
| id: hoursInputId, | ||
| label: hoursLabel, | ||
| "aria-label": hoursAriaLabel, | ||
| "aria-label": hoursInputAriaLabel, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: |
||
| error: hoursError, | ||
| warning: hoursWarning, | ||
| } = hoursInputProps; | ||
| const { | ||
| id: minutesInputId, | ||
| label: minutesLabel, | ||
| "aria-label": minutesAriaLabel, | ||
| "aria-label": minutesInputAriaLabel, | ||
| error: minutesError, | ||
| warning: minutesWarning, | ||
| } = minutesInputProps; | ||
|
|
@@ -168,9 +172,10 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| const [period, setPeriod] = useState(toggleValue); | ||
| const hrsLabel = hoursLabel || locale.time.hoursLabelText(); | ||
| const minsLabel = minutesLabel || locale.time.minutesLabelText(); | ||
| const hrsAriaLabel = hoursAriaLabel || locale.time.hoursAriaLabelText(); | ||
| const hrsAriaLabel = | ||
| hoursInputAriaLabel || locale.time.hoursAriaLabelText(); | ||
| const minsAriaLabel = | ||
| minutesAriaLabel || locale.time.minutesAriaLabelText(); | ||
| minutesInputAriaLabel || locale.time.minutesAriaLabelText(); | ||
| const hoursRef = useRef<HTMLInputElement>(null); | ||
| const minsRef = useRef<HTMLInputElement>(null); | ||
|
|
||
|
|
@@ -202,11 +207,11 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| const computedValidations = ( | ||
| hrs?: string | boolean, | ||
| mins?: string | boolean, | ||
| ) => { | ||
| ): string | undefined => { | ||
| const hoursIsString = typeof hrs === "string"; | ||
| const minutesIsString = typeof mins === "string"; | ||
| if (!hoursIsString && !minutesIsString) { | ||
| return hrs || mins; | ||
| return undefined; | ||
| } | ||
|
|
||
| if (hoursIsString && !minutesIsString) { | ||
|
|
@@ -240,8 +245,9 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| ev: React.ChangeEvent<HTMLInputElement>, | ||
| inputName: "hrs" | "mins", | ||
| ) => { | ||
| const hours = inputName === "hrs" ? ev.target.value : inputValues[0]; | ||
| const minutes = inputName === "mins" ? ev.target.value : inputValues[1]; | ||
| const rawValue = ev.target.value.replace(/[^0-9]/g, ""); | ||
|
tomdavies73 marked this conversation as resolved.
|
||
| const hours = inputName === "hrs" ? rawValue : inputValues[0]; | ||
| const minutes = inputName === "mins" ? rawValue : inputValues[1]; | ||
| setInputValues([hours, minutes]); | ||
|
|
||
| const formattedHours = hours.length ? hours.padStart(2, "0") : hours; | ||
|
|
@@ -304,12 +310,9 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
|
|
||
| return ( | ||
| <Fieldset | ||
| applyNewValidation | ||
| id={internalId.current} | ||
| legend={label} | ||
| inputHint={inputHint} | ||
| width="min-content" | ||
| legendAlign={labelAlign} | ||
| legend={legend || label} | ||
| legendHint={legendHint || inputHint} | ||
| isRequired={required} | ||
| isDisabled={disabled} | ||
| name={name} | ||
|
|
@@ -325,15 +328,15 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| > | ||
| <Box display="flex" className="time"> | ||
| <div> | ||
| <StyledLabel | ||
| aria-label={hrsAriaLabel} | ||
| <Label | ||
| htmlFor={internalHrsId.current} | ||
| size={size} | ||
| disabled={disabled} | ||
| align={fieldLabelsAlign} | ||
| readOnly={readOnly} | ||
| > | ||
| {hrsLabel} | ||
| </StyledLabel> | ||
| <Number | ||
| </Label> | ||
| <Textbox | ||
| {...hoursInputProps} | ||
| label={undefined} | ||
| data-component="hours" | ||
|
|
@@ -347,8 +350,11 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| warning={!!hoursWarning} | ||
| disabled={disabled} | ||
| readOnly={readOnly} | ||
| required={required} | ||
| maxWidth={SIZES[size]} | ||
| my={0} // prevents any form spacing being applied | ||
| inputMode="numeric" | ||
| aria-label={hrsAriaLabel} | ||
| /> | ||
| </div> | ||
| <Box | ||
|
|
@@ -359,20 +365,24 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| aria-hidden="true" | ||
| > | ||
| <span> </span> | ||
| <Typography isDisabled={disabled} variant="span" mb="-4px"> | ||
| <StyledColon | ||
| $size={size} | ||
| $isDisabled={disabled} | ||
| $isReadOnly={readOnly} | ||
| > | ||
| : | ||
| </Typography> | ||
| </StyledColon> | ||
| </Box> | ||
|
nuria1110 marked this conversation as resolved.
|
||
| <div> | ||
| <StyledLabel | ||
| aria-label={minsAriaLabel} | ||
| <Label | ||
| htmlFor={internalMinsId.current} | ||
| size={size} | ||
| disabled={disabled} | ||
| align={fieldLabelsAlign} | ||
| readOnly={readOnly} | ||
| > | ||
| {minsLabel} | ||
| </StyledLabel> | ||
| <Number | ||
| </Label> | ||
| <Textbox | ||
| {...minutesInputProps} | ||
| label={undefined} | ||
| data-component="minutes" | ||
|
|
@@ -386,8 +396,11 @@ const Time = React.forwardRef<TimeHandle, TimeProps>( | |
| warning={!!minutesWarning} | ||
| disabled={disabled} | ||
| readOnly={readOnly} | ||
| required={required} | ||
| maxWidth={SIZES[size]} | ||
| my={0} // prevents any form spacing being applied | ||
| inputMode="numeric" | ||
| aria-label={minsAriaLabel} | ||
| /> | ||
| </div> | ||
| {showToggle && ( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,33 @@ | ||
| import styled from "styled-components"; | ||
| import Label from "../../__internal__/legacy-label"; | ||
| import styled, { css } from "styled-components"; | ||
|
|
||
| const StyledLabel = styled(Label)` | ||
| label { | ||
| font-weight: var(--fontWeights400); | ||
| } | ||
| const colonFontBySize = { | ||
| small: "var(--global-font-static-comp-regular-s)", | ||
| medium: "var(--global-font-static-comp-regular-m)", | ||
| large: "var(--global-font-static-comp-regular-l)", | ||
| }; | ||
|
|
||
| type StyledColonProps = { | ||
| $size: "small" | "medium" | "large"; | ||
| $isDisabled?: boolean; | ||
| $isReadOnly?: boolean; | ||
| }; | ||
|
|
||
| const StyledColon = styled.span<StyledColonProps>` | ||
| ${({ $size, $isDisabled, $isReadOnly }) => css` | ||
| font: ${colonFontBySize[$size]}; | ||
| color: var(--input-typical-txt-default); | ||
| text-align: center; | ||
|
|
||
| ${$isReadOnly && | ||
| css` | ||
| color: var(--input-typical-txt-read-only); | ||
| `} | ||
|
|
||
| ${$isDisabled && | ||
| css` | ||
| color: var(--input-typical-txt-disabled); | ||
| `} | ||
| `} | ||
| `; | ||
|
|
||
| export default StyledLabel; | ||
| export default StyledColon; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
suggestion: if you're adding this to the prop description you should also add it to any other props within
TimeInputPropsfor consistency sakeThere 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.
Done ✅