question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

should type be constrained by maxLength?

See original GitHub issue

Is maxLength an attribute user-event should take into account?

If so, the following test should pass:

// __tests__/vue/type.js

test("maxlength", () => {
  const input = jest.fn();

  const maxlength = 10;

  const { getByTestId } = renderComponent('input',
    { input },
    { maxlength }
  );

  const text = "Hello, world!";
  userEvent.type(getByTestId("input"), text);

  expect(input).toHaveBeenCalledTimes(maxlength);
  expect(getByTestId("input")).toHaveProperty("value", text.slice(0, maxlength));
});

I’ll be happy to implement it if you think it makes sense.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Gpxcommented, Sep 25, 2019

It looks like the browser doesn’t fire the events if the max length is reached: link. Since user-event is the one responsible for firing events I think the check should happen on our side rather than with JSDOM.

What do you think?

1reaction
weyertcommented, Sep 24, 2019

Sounds good to me. I can work on something tomorrow at work

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML attribute: maxlength - MDN Web Docs
The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> ....
Read more >
maxlength ignored for input type="number" in Chrome
So maxlength is ignored on <input type="number"> by design. Depending on your needs, you can use the min and max attributes as inon...
Read more >
maxlength Constraint Validation Oddities in Major Browsers
Constraint validation is an HTML5 spec that provides native client side form validation in the browser. As part of its API, all <input>...
Read more >
maxlength constraint for text box` | SAP Community
hi, I want to make a textbox to accept only 2 digits.. if i give maxlength="2" its not working..how will i acheive this?...
Read more >
GraphQL validation using directives
@constraint(pattern: "^[0-9a-zA-Z]*$", maxLength: 255) } type Mutation { signUp(input: SignUpInput!) } Before we move on, it's good to mention ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found