mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-03-24 04:02:54 -04:00
Autosize textboxes w/out highlighting placeholders
Scrolling within textareas on the page is a bit grim. Which is why we don’t do it for the textboxes that people use to edit templates. This commit will allow us to extend the auto-resizing of `<textarea>`s to those which don’t need the highlighting of placeholders. The code is still quite coupled to the placeholder highlighting code, because both work by copying the content of the `<textarea>` into a `<div>` that underlaps the textbox. This `<div>` is used for both rendering the placeholder highlights, and calculating the natural height of the content. So it would be hard/confusing to split the two bits of code into separate modules.
This commit is contained in:
@@ -125,6 +125,34 @@ describe('Highlight tags', () => {
|
||||
|
||||
});
|
||||
|
||||
describe("The element's width should match even when the textbox is initially hidden", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
let setDisplayPropertyOfFormGroups = function(property) {
|
||||
Array.prototype.forEach.call(
|
||||
document.getElementsByClassName('form-group'),
|
||||
element => element.style.display = property
|
||||
);
|
||||
};
|
||||
|
||||
setDisplayPropertyOfFormGroups('none');
|
||||
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
setDisplayPropertyOfFormGroups('block');
|
||||
|
||||
});
|
||||
|
||||
test("If the textbox is an <textarea>", () => {
|
||||
|
||||
backgroundEl = textarea.nextElementSibling;
|
||||
expect(backgroundEl.style.width).toEqual('582px');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test("The element should be hidden from assistive technologies", () => {
|
||||
|
||||
expect(backgroundEl.getAttribute('aria-hidden')).toEqual('true');
|
||||
@@ -167,6 +195,22 @@ describe('Highlight tags', () => {
|
||||
|
||||
});
|
||||
|
||||
test("Unless a data attribute is set to turn this feature off", () => {
|
||||
|
||||
textarea.textContent = "Dear ((title)) ((name))";
|
||||
textarea.setAttribute('data-highlight-placeholders', 'false')
|
||||
|
||||
// start module
|
||||
window.GOVUK.modules.start();
|
||||
|
||||
backgroundEl = textarea.nextElementSibling;
|
||||
|
||||
const highlightTags = backgroundEl.querySelectorAll('.placeholder');
|
||||
|
||||
expect(highlightTags.length).toEqual(0);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("If there is optional text in the content, its matching text in the element below should be wrapped in a highlight tag", () => {
|
||||
|
||||
Reference in New Issue
Block a user