Commit Graph

185 Commits

Author SHA1 Message Date
Tom Byers
bb16626209 Split module out into objects for each component
Is clearer than just having one large hierarchical
object and makes the relationships between the
module and its components clearer.
2019-05-10 14:20:14 +01:00
Tom Byers
7328649537 Combine 'Change' and 'Done' buttons into one
Includes addition of classes by JS to ensure CSS
selectors don't have to reference the data
attributes.
2019-05-10 14:16:03 +01:00
Chris Hill-Scott
923ac7190c Add a hint when no team members are selected
This helps clarify that you will still be able to see the folder.
Follows the phrasing used for the "No folders…" message.
2019-05-09 13:43:04 +01:00
Tom Byers
1ffa8c8915 Only show the folder icon if fields are folders 2019-05-09 11:25:28 +01:00
Tom Byers
db12ec3a5c Make buttons work outside of context
This is important for users who find buttons via
interfaces that present them out of the context of
the page, like screenreaders.
2019-05-08 17:16:08 +01:00
Tom Byers
42a9a0cf23 Make selection summary a live region
Live regions need to be in the original HTML of
the page to work. We were generating the summary
in JS.

This changes the JS to only generate the contents
of the summary so changes to its contents are
announces by the existing live-region.
2019-05-08 17:16:06 +01:00
Tom Byers
33d074c00a Allow nested checkboxes to be collapsible
Expands the API of the macro to allow nested
checkboxes to have a summary tracking the current
selection, the fieldset to expand/collapse and
buttons to be added to allow jumping between
states.

Includes making 'Done' button inline on mobile.
Helps differentiate it form the form submit.
2019-05-08 17:08:16 +01:00
Tom Byers
b3d73030ee Remove use of spread operator
This is a temporary fix for the fact that the
babel plugin for the spread operator calls a
function called `_iterableToArray` which assumes
the JavaScript runtime supports Symbols.

IE11 doesn't support Symbols so this causes an
error when it runs our JS.

This swaps out use of the spread operator for a
use of
[apply](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
to unpack the `arguments` object.

Related issue on babel:

https://github.com/babel/babel/issues/7597
2019-04-17 12:40:49 +01:00
Tom Byers
1d88324175 Revert "Update diff-dom package to 3.1.0"
This reverts commit 01b97986f6.
2019-04-16 13:09:15 +01:00
Tom Byers
01b97986f6 Update diff-dom package to 3.1.0
Since it moved to ES Modules in version 2.3.1,
diff-dom stopped including the `diffDOM.js` file
in its NPM package.

We don't do any kind of bundling in our build yet,
just concatenation of our scripts and some
minification of the results so we can't take
advantage of this yet.

The `diffDOM.js` file is still available in the
Github release so this moves to referencing that
in the `package.json` instead, until we start
using a bundler.

I opened an issue to check this is what the author
intended:

https://github.com/fiduswriter/diffDOM/issues/84

The latest version also adds Rollup as a peer
dependency.
2019-04-12 15:36:57 +01:00
Tom Byers
cb55fbb344 Fix reference to non-existent jQuery collection
Raised on PR as comment:

e4b4be9d45 (r270781103)
2019-04-03 14:41:09 +01:00
Tom Byers
8d5e7e70ab Prevent autofocus when page has scrolled
If users scroll a page with an autofocus component
on so it is off-screen it seems safe to assume
they won't want it focused if they return to it.

This prevents that happening.

This adds a data-attribute flag to allow this
behaviour to be overridden.

We have some situations where the assumption here
isn't appropriate, for example on pages where the
component with autofocus is in a sticky element.
This means it will appear offscreen when the page
loads but, when its parent becomes sticky, will be
visible again.
2019-04-03 14:41:09 +01:00
Tom Byers
a426cae968 Remove overlap check for elements in sticky
Our sticky controls often contain focusable
elements.
2019-03-25 15:59:32 +00:00
Tom Byers
8ad4c5e6e1 Add separate overlap handling for textareas
Our textareas are multi-line and can change in
size based on their content.

Because of this, we need to check the caret for
overlapping, not the whole textarea.

This adds separate tracking for this.
2019-03-25 15:59:32 +00:00
Tom Byers
5ba2bd66e0 Revert "Merge pull request #2855 from alphagov/revert-2843-stop-sticky-overlapping-focus"
This reverts commit 0f9969989a, reversing
changes made to 42e3770e65.
2019-03-25 15:58:23 +00:00
Tom Byers
4e7e934e25 Revert "Prevent sticky controls overlapping focus" 2019-03-18 16:38:49 +00:00
Tom Byers
3b0fd4a92c Make controls re-render only when state changed
Adds a guard around all calls to `.render()` after
the first one (which sets the initial state) to
prevent DOM manipulation when not needed.

The original behaviour meant the action buttons
were re-rendered when items from the list of
templates/folders were selected/deselected, even
if the state hadn't changed. This meant, in some
cases, focus was shifted to the buttons when you
were still selecting/deselecting.
2019-03-18 11:25:26 +00:00
Tom Byers
b8c5ab5e38 Handle overlaps in scroll areas on focus events
When focus changes in scroll areas, check the
current focused element isn't overlapped by sticky
elements in the area.

If there are overlaps, mimic what browsers do if
focus moves outside the viewport and scroll to
move the focused element into view.
2019-03-18 11:25:26 +00:00
Tom Byers
b13bc158ac Add object to manage scroll areas for stickys 2019-03-18 11:25:26 +00:00
Tom Byers
d0aee7887b Allow setting of scroll area explicitly
Defaults to scroll area being the parent element
of the sticky element, if not set.
2019-03-18 11:25:25 +00:00
Tom Byers
14553dcfd0 Give context to 'Cancel' and 'Clear' links
Links need to work in isolation from their context
in the page.

This is an attempt at doing that. The one for
'Cancel' is still not ideal but 'Clear selection'
gives more information than 'Clear' about what it
does.

Also adds a 'href' attribute to the link, without
which its accessible role isn't recognised.
2019-02-21 13:27:18 +00:00
Tom Byers
2d85469cd0 Move 'Clear' link out of 'aria-hidden' region 2019-02-21 13:27:18 +00:00
Tom Byers
15104e9d25 Re-position live-region to remove duplication
Adding a visually hidden live-region creates
duplication in the HTML. End result for users of
screen readers are that you get the same text read
out twice.

This adds `aria-hidden` to hide the visible
version and re-positions the live-region one next
to it. That means the live-region text appears in
the same place in the document order as the
visible one so things are announced as expected.
2019-02-21 13:27:18 +00:00
Tom Byers
050a513cf5 Update a11y API when selection count changes
Inserts a hidden live region to ensure changes to
the count are announced.

The live region is hidden because it needs to be
in the initial markup of the page. The visual
counter is part of a larger region which is
inserted/removed from the DOM.

See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
2019-02-21 13:26:14 +00:00
Tom Byers
a8cac953d7 Deal with lost focus when selection cleared
This was missed out of the work on improving focus
on the templates page.

When you clear the current selection, the 'clear'
link disappears so focus needs to be sent
somewhere.
2019-02-21 13:26:14 +00:00
karlchillmaid
03a2b28269 Corrected: Add to new folder button
Corrected: Add to new folder button
2019-02-20 14:58:14 +00:00
Katie Smith
44781e3b69 Change preview pane JS to preview letters as well as emails 2019-02-19 10:44:51 +00:00
Katie Smith
83c10149bd Rename 'email-branding-preview' CSS styles to 'branding-preview'
Renamed since the same styling will be used for previewing letters.
2019-02-19 10:44:51 +00:00
Tom Byers
994c9397fe Fix the logic handling spacing between stickys 2019-02-13 14:49:42 +00:00
Tom Byers
30844143ec Fix bugs around operations happening between modes
The `release` method is meant to clean up a sticky
element before removal from the store.

The part of this that cleared CSS added due to
being in dialog mode was only run if still in that
mode.

In the template folder JS, we set the mode before
running `recalculate` so elements can be cleaned
in a different mode to that they were last in.
This meant some CSS wasn't being cleaned up.

This sometimes caused an effect where elements
that were added back to the DOM but not stuck
would still have CSS used when they were last
stuck.

This commit also includes the addition of some
missing code that adds back CSS to offset an
element when in a dialog stack.
2019-02-11 17:50:47 +00:00
Tom Byers
09848009c1 Correct reference to 'self' variable
It doesn't exist in this scope so the 'self' in
the scope above was being referenced instead,
preventing it from erroring.
2019-02-11 16:10:29 +00:00
Tom Byers
4c477d08a6 Put shift in focus after change to state
Moving focus before letting the sticky JS set the
position of sticky elements means focus is shifted
to them when they are still in the page. This
causes the browser to scroll so the focused
elements are visible.

This moves when focus is set to after the sticky
JS has set position therefore avoiding the issue.
2019-02-11 15:24:09 +00:00
Tom Byers
693ddadbc4 Deal with focus state following cancelation
Follows pattern from dialogs whereby focus returns
to the button/link that fired the dialog when it
closes.
2019-02-11 15:24:09 +00:00
Tom Byers
d633bdbb6d Tidy up JS code for focusing & associated html
Makes sure the tabindex we add for focusing is
removed.

Also removes the outer fieldset from the radios
for new templates. We don't wrap form buttons in
fieldsets anywhere else and it doesn't add any
useful semantics to the form.
2019-02-11 15:24:09 +00:00
Tom Byers
2b2641b039 Use JS for applying focus & add styling for it
Adds some extra styles so <fieldset>'s show as
focused when they are.

Also includes replacement of `overflow: hidden` on
sticky elements with a clearfix. hiding overflow
clips the outline and the clearfix can be used for
containing any floats instead. (I'm assuming that's
why it was set here.)
2019-02-11 15:24:09 +00:00
Chris Hill-Scott
ca6529dcdb Update app/assets/javascripts/templateFolderForm.js
Use native `Array.indexOf` instead.

Co-Authored-By: tombye <tombaromba@gmail.com>
2019-02-04 15:17:27 +00:00
Tom Byers
0e55521d8f $.inArray returns the same value as Array.indexOf 2019-02-04 14:56:18 +00:00
Tom Byers
7ef32a6bd9 Replace native Array.includes with jQuery version
This was failing with a 'Object doesn't have
method' error on IE11. Assume Babel wasn't
polyfilling Array.includes so reverting to jQuery
version for now.
2019-02-04 11:23:41 +00:00
Chris Hill-Scott
5597e63d44 Recalculate stickyness after API keys have rendered 2019-02-01 15:45:38 +00:00
Tom Byers
fd3ca31e44 Add adjustment for padding missed from previous
The work done to stack sticky elements closer
together only effected the stack when stuck to the
top/bottom edge:

707c426b9a

It should have included the same for when a stack
of sticky elements is stopped at the end of it's
scroll area. This adds code to deal with that.
2019-01-31 15:56:16 +00:00
Tom Byers
c89ad9635b Fix switch between modes and scrolling on adjust
The templateFolderForm JS was setting the mode to
'dialog' but not back when the state was changed
back to a normal sticky element. This caused
adjustments and scrolling when no adjustment
needed to be accommodated.

There were also problems with adjustForResize. It
was manipulating the same flag that resizing the
window did and returned a value never used.
2019-01-30 19:12:14 +00:00
Tom Byers
707c426b9a Remove padding between stickys when stacked 2019-01-30 14:59:30 +00:00
Tom Byers
f4d9c37940 Move setting of sticky mode out of recalculate
The `recalculate` method currently does three
things:
1. sync's the internal store with the DOM
2. updates the saved positional and dimensional
data from the new DOM
3. allows the mode to be set

The problem with using it as the way to set the
mode is that, every call to it is effectively
setting the mode but this isn't always the
intention.

This splits off setting the mode so other modules
have to explicity set it and those that don't
intend to can just call `recalculate` to notify of
DOM changes.
2019-01-30 11:45:24 +00:00
Tom Byers
177f30248e Fix bug with DOM sync'ing
If a sticky element was already in the store, the
code for adding it would return early. This meant
dimensions and positions for it were not being
recalculated.
2019-01-30 11:35:31 +00:00
Leo Hemsted
d5e95af446 make classes in folder dialog states consistent
make sure the class is applied to a child element, so that `$el.find`
will always find something for `js-will-stick-at-bottom-when-scrolling`.

Also, clean up code by treating all stickies on the template folder
form as dialogs - they all are after all all dialogs - modals that
expect your attention on top of the main page content.
2019-01-25 16:47:49 +00:00
Tom Byers
05c455250c Fix calculation of in-page position
When the screen resizes, the dimensions of our
elements may change so we run
`setElementDimensions` again to update our store
of those values.

This caused a bug with the stored position of
stuck elements. When stuck, elements are
'fixed' so their position is relative to the
window position. We need the value stored to be
from the position in the document flow, not the
'fixed' value.

This change means, when an element is stuck, we
check its shim for the position instead. The shim
occupies the space the element would do in the
page so it makes sense to use it for this.
2019-01-23 16:55:18 +00:00
Tom Byers
59b02e0fe0 Change when folder controls become sticky
The controls for the template folders are all
present in the page when it loads. The
templateFolderForm JS filters them so you only see
the one you need to for the thing you're trying to
do.

This changes when the controls are made sticky so
it happens after the templateFolderForm JS has
performed its filtering.
2019-01-23 16:55:18 +00:00
Tom Byers
98789c98c8 Reset onload flag when recalculate called
This ensures sticky elements don't fade in if
in a sticky position when the page loads.

The fade is there to show when an element is
becoming sticky. This has no use if it was already
sticky the first time you see it.

Because the same situation applies when
recalculate is called, we also want the flag to be
reset before this happens.
2019-01-23 16:55:18 +00:00
Tom Byers
a9b7a0d887 Add box shadow by JS
When mode === 'dialog', sticky elements are
stacked so we need to apply the box shadow to the
top (when sticking to the bottom edge) and bottom
(when sticking to the top edge) elements in the
stack.

From what I can see, we need the version of
`nth-child` that supports targeting by selector.
As of this date, support for this is only in
Safari:

https://caniuse.com/#feat=css-nth-child-of

Until we can use this version of `nth-child`, we
need to use JS to apply the styles.
2019-01-23 16:55:18 +00:00
Tom Byers
4e845c3125 Move setting of events into separate method 2019-01-23 16:55:18 +00:00