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

Add story for disabled form, fix bugs #1008

Open
wants to merge 1 commit into
base: release-146
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/elements/input/GeolocationInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const GeolocationInput: React.FC<GeolocationInputProps> = ({
buttonRef.current?.focus(); // move focus to Request Location button
}}
startIcon={<ClearIcon />}
disabled={disabled}
>
Clear Map
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/components/elements/input/SsnInput.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default {
label: { control: 'text' },
onlylast4: { control: 'boolean' },
value: { control: 'text' },
disabled: { control: 'boolean' },
},
render: (args: any) => {
const [{ value }, updateArgs] = useArgs();
Expand Down
5 changes: 3 additions & 2 deletions src/components/elements/input/SsnInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const SsnInput = ({
chars: 3,
inputProps: {
...baseInputProps,
disabled: onlylast4 ? true : false,
disabled: baseInputProps.disabled || onlylast4 ? true : false,
inputProps: {
...baseInputProps.inputProps,
'aria-label': ariaLabel + ' first 3 digits',
Expand All @@ -96,7 +96,7 @@ const SsnInput = ({
chars: 2,
inputProps: {
...baseInputProps,
disabled: onlylast4 ? true : false,
disabled: baseInputProps.disabled || onlylast4 ? true : false,
placeholder: 'XX',
inputProps: {
...baseInputProps.inputProps,
Expand Down Expand Up @@ -135,6 +135,7 @@ const SsnInput = ({
sx={{ maxWidth, ...sx }}
label={label}
helperText={helperText}
LabelProps={{ disabled: baseInputProps.disabled }}
>
<Box
sx={{
Expand Down
26 changes: 25 additions & 1 deletion src/modules/form/components/DynamicForm.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import { Default as ViewStory } from './viewable/DynamicView.stories';
import { emptyErrorState } from '@/modules/errors/util';
import formData from '@/test/__mocks__/mockFormDefinition.json';
import { generateMockValuesForDefinition } from '@/test/utils/testUtils';
import { FormDefinitionJson, ItemType } from '@/types/gqlTypes';
import {
DisabledDisplay,
EnableOperator,
FormDefinitionJson,
ItemType,
} from '@/types/gqlTypes';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const formDefinition: FormDefinitionJson = JSON.parse(JSON.stringify(formData));

export default {
component: DynamicForm,
argTypes: { label: { control: 'text' } },
parameters: {
docs: { disable: true }, // don't render every story on the docs tab
},
decorators: [
(Story) => (
<Box>
Expand Down Expand Up @@ -69,6 +77,22 @@ WithValuesAsReadOnly.args = {
errors: emptyErrorState,
};

export const WithDisabledInputs = Template.bind({});
WithDisabledInputs.args = {
definition: modifyFormDefinition(formDefinition, (item) => {
item.enableWhen = [
{
question: 'string-1',
operator: EnableOperator.Equal,
answerCode: 'foo',
},
];
item.disabledDisplay = DisabledDisplay.ProtectedWithValue; // show values
}),
initialValues: ViewStory.args?.values,
errors: emptyErrorState,
};

// Render a mini form that doesn't have a top-level group
const miniForm = {
item: [
Expand Down
Loading