@ministryofjustice/frontend 2.2.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,24 @@
1
1
  .moj-page-header-actions {
2
- @include govuk-clearfix;
3
- font-size: 0; // Hide whitespace between elements
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ justify-content: space-between;
5
+ align-items: center;
6
+ gap: govuk-spacing(2);
4
7
  margin-bottom: govuk-spacing(7);
5
8
  min-height: govuk-spacing(7); // Match button height
6
- text-align: justify; // Trick to remove the need for floats
7
- &:after {
8
- content: '';
9
- display: inline-block;
10
- width: 100%;
11
- }
12
-
13
9
  }
14
10
 
15
-
16
11
  .moj-page-header-actions__title {
17
-
18
- [class^=govuk-heading-] {
19
- margin-bottom: govuk-spacing(2);
20
- text-align: left;
21
- @include govuk-media-query($from: tablet) {
22
- margin-bottom: 0;
23
- }
24
- }
25
-
26
- @include govuk-media-query($from: tablet) {
27
- display: inline-block;
28
- vertical-align: middle;
12
+ [class^="govuk-heading-"] {
13
+ margin-bottom: 0;
29
14
  }
30
-
31
15
  }
32
16
 
33
-
34
17
  .moj-page-header-actions__actions {
35
-
36
- @include govuk-media-query($from: tablet) {
37
- display: inline-block;
38
- vertical-align: middle;
39
- }
40
-
41
- }
42
-
43
- .moj-page-header-actions__action {
44
-
45
- &:last-child {
18
+ .moj-button-group {
46
19
  margin-bottom: 0;
47
20
  }
48
-
49
- @include govuk-media-query($from: tablet) {
21
+ .govuk-button {
50
22
  margin-bottom: 0;
51
23
  }
52
-
53
24
  }
54
-
@@ -1,20 +1,20 @@
1
1
  {%- from "moj/components/button-menu/macro.njk" import mojButtonMenu %}
2
+ {% from "govuk/macros/attributes.njk" import govukAttributes %}
3
+ {%- from "govuk/components/button/macro.njk" import govukButton %}
2
4
 
3
- <div class="moj-page-header-actions {{- ' ' + params.classes if params.classes}}" {%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
4
-
5
- <div class="moj-page-header-actions__title">
6
- <h{{ params.heading.level | default(1) }} class="{{params.heading.classes | default('govuk-heading-xl')}}">
7
- {{- params.heading.html | safe if params.heading.html else params.heading.text -}}
8
- </h{{ params.heading.level | default(1) }}>
9
- </div>
10
-
11
- {% if params.items %}
12
- <div class="moj-page-header-actions__actions">
13
- {{mojButtonMenu({
14
- buttonClasses: 'moj-page-header-actions__action',
15
- items: params.items
16
- })}}
5
+ <div class="moj-page-header-actions {{- ' ' + params.classes if params.classes}}" {{- govukAttributes(params.attributes) -}}>
6
+ <div class="moj-page-header-actions__title">
7
+ <h{{ params.heading.level | default(1) }} class="{{ params.heading.classes | default("govuk-heading-xl") }}">
8
+ {{- params.heading.html | safe if params.heading.html else params.heading.text -}}
9
+ </h{{ params.heading.level | default(1) }}>
17
10
  </div>
18
- {% endif %}
19
-
11
+ {% if params.items %}
12
+ <div class="moj-page-header-actions__actions">
13
+ <div class="moj-button-group moj-button-group--inline">
14
+ {% for button in params.items %}
15
+ {{ govukButton(button) }}
16
+ {% endfor %}
17
+ </div>
18
+ </div>
19
+ {% endif %}
20
20
  </div>
@@ -29,3 +29,4 @@ MOJFrontend.PasswordReveal.prototype.onButtonClick = function() {
29
29
  this.button.html('Show <span class="govuk-visually-hidden">password</span>');
30
30
  }
31
31
  };
32
+
@@ -0,0 +1,46 @@
1
+ const { getByDisplayValue, getByText } = require("@testing-library/dom");
2
+ const { axe } = require("jest-axe");
3
+
4
+ require("./password-reveal.js");
5
+
6
+ describe("Password reveal", () => {
7
+ let container;
8
+
9
+ beforeEach(() => {
10
+ const input = document.createElement("input");
11
+ input.type = "password";
12
+ input.value = "password";
13
+
14
+ new MOJFrontend.PasswordReveal(input);
15
+
16
+ container = input.parentNode;
17
+ });
18
+
19
+ test("initialises container", () => {
20
+ expect(container).toHaveClass("moj-password-reveal");
21
+ expect(container).toContainElement(getByText(container, "Show"));
22
+ });
23
+
24
+ test("toggle reveal", () => {
25
+ const input = getByDisplayValue(container, "password");
26
+ const button = getByText(container, "Show");
27
+
28
+ button.click();
29
+
30
+ expect(input).toHaveAttribute("type", "text");
31
+ expect(button).toHaveTextContent("Hide");
32
+
33
+ button.click();
34
+
35
+ expect(input).toHaveAttribute("type", "password");
36
+ expect(button).toHaveTextContent("Show");
37
+ });
38
+
39
+ test("accessibility", async () => {
40
+ const button = getByText(container, "Show");
41
+
42
+ expect(await axe(document.body)).toHaveNoViolations();
43
+ button.click();
44
+ expect(await axe(document.body)).toHaveNoViolations();
45
+ });
46
+ });
@@ -1,3 +1,4 @@
1
1
  @import "width-container";
2
2
  @import "filter-layout";
3
3
  @import "scrollable-pane";
4
+ @import "button-group";
@@ -0,0 +1,37 @@
1
+
2
+ .moj-button-group {
3
+ $horizontal-gap: govuk-spacing(3);
4
+ $vertical-gap: govuk-spacing(3);
5
+ $button-shadow-size: $govuk-border-width-form-element;
6
+
7
+ @extend .govuk-button-group;
8
+
9
+
10
+ &--inline {
11
+ flex-direction: row;
12
+ flex-wrap: wrap;
13
+ align-items: baseline;
14
+ gap: $horizontal-gap;
15
+ margin-right: 0;
16
+
17
+ .moj-button-menu {
18
+ margin-bottom: $vertical-gap + $button-shadow-size;
19
+ }
20
+
21
+ .moj-button-menu .moj-button-menu__toggle-button {
22
+ vertical-align: baseline;
23
+ }
24
+
25
+ .moj-button-menu,
26
+ .govuk-button,
27
+ .govuk-link {
28
+ width: auto;
29
+ margin-right: 0;
30
+ margin-bottom: 0;
31
+ }
32
+
33
+ /* :is(.govuk, .moj-button-menu, .govuk-link) + :is(.govuk, .moj-button-menu, .govuk-link) { */
34
+ /* margin-top: $horizontal-gap; */
35
+ /* } */
36
+ }
37
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/frontend",
3
3
  "description": "The MOJ Frontend contains the code you need to start building user interfaces for UK Ministry of Justice government services.",
4
- "version": "2.2.3",
4
+ "version": "3.0.0",
5
5
  "main": "moj/all.js",
6
6
  "sass": "moj/all.scss",
7
7
  "engines": {