-
Notifications
You must be signed in to change notification settings - Fork 4
Stepper component for use on the additional image details form #955
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
base: main
Are you sure you want to change the base?
Conversation
5109562 to
6f1f116
Compare
6f1f116 to
707124a
Compare
|
The review app is available at this URL: |
707124a to
fd4995b
Compare
fd4995b to
2d0bd7a
Compare
2d0bd7a to
cd6d31c
Compare
|
|
||
| // Polyfill default value on step up | ||
| if (isEmpty && event?.currentTarget === this.$buttonStepUp) { | ||
| $input.valueAsNumber = min === 0 ? 1 : min |
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 is the polyfill I changed. If the input is blank and min is 0, step up sets it to 1, not 0.
|
|
||
| beforeEach(async () => { | ||
| document.body.innerHTML = ` | ||
| <div class="nhsuk-form-group app-stepper-input" data-module="app-stepper-input" data-max="20" data-min="0"> |
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.
it's awkward having to specify all this HTML here... for the nhsuk-frontend version, we can just render the nunjucks macro. I considered bringing in nunjucks as a dependency and rendering the jinja component as if it was nunjucks, but I thought this would complicate things too much.
| expect(liveRegion.innerText).toBe('2') | ||
| }) | ||
|
|
||
| it('assumes the min value when stepping down if the input is empty', async () => { |
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.
Note: these two tests are technically testing jsdom, as this behaviour is normally provided by a browser, but I thought it was worth including as it helps to document the intended behaviour.
| .nhsuk-form-group .app-button--link { | ||
| display: block; | ||
| } | ||
|
|
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 scss is all unchanged from the nhsuk-frontend PR, excpept I've renamed the class prefixes to app-
| @@ -0,0 +1,40 @@ | |||
| {# | |||
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 might become obsolete soon if the icons are accepted into the design system, but I copied the macro structure as I thought it would be handy to have. If we need another custom SVG at any point we can just add it here.
This allows timeouts to cause a redirect to the persona login in local dev.
This repurposes Colin's proposed code for the design system. See nhsuk/nhsuk-frontend#1719 I've stripped out a few options that we don't need right now in order to focus on the use case we have. Should this be accepted into the design system, we'll back out these changes, but the way we call the component will be very similar.
This extends our existing version of IntegerField so that it renders with a stepper when the StepperInput widget is specified.
bc8c847 to
97dd7a2
Compare
|
|
|
||
| def test_renders_stepper_input(self, form_class): | ||
| actual = form_class()["stepper_field"].as_field_group() | ||
| expected = render_to_string( |
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 figured out I could render the underlying component like this to simplify the test. This means the test is not sensitive to the implementation of the jinja component, only that we pass through the right params from the field to the component.
We should do this for the other fields too but I didn't want to overload this PR.



Description
This brings in a version of the stepper component as
app-stepper-input, and wires it up to the customisedIntegerFieldin the nhsforms app.Example usage:
At the time of writing, the additional image details form is not merged yet, but I can update that to use this component when it is.
Note: I've added a little debug page at /debug/components in order to preview components like this that are not coming from the design system. This is not enabled in the review environments as I don't intend to be visible except for developers running in DEBUG mode. If you prefer, I can remove this page, but I found useful for manual testing.
Jira link
https://nhsd-jira.digital.nhs.uk/browse/DTOSS-12115
Review notes
Post merge tasks
Review checklist