Skip to content
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

Error when attempting to fillIn/typeIn a disabled form control #741

Merged
merged 1 commit into from
Apr 21, 2020

Conversation

ro0gr
Copy link
Contributor

@ro0gr ro0gr commented Nov 21, 2019

fixes: #680
continues: #681

With this PR fillIn and typeIn helpers start to fail on attempt to interact with disabled form controls.

There is a follow up PR, doing a similar thing for readonly(#779). Extracted it to make review easier.


my original intention was also to cover click and doubleclick and the rest of interaction helpers with the same logic, but seems they intentionally just skip focus for non-focusable elements:

if (isFocusable(element)) {
__focus__(element);
}

Assuming changing of this behavior, might be considered a breaking change, I've extracted this part as a separate follow-up PR(#778)

@ro0gr
Copy link
Contributor Author

ro0gr commented Nov 21, 2019

not sure what does fail on CI, it just says:

The command "yarn test" exited with 139.

w/o any context.

@ro0gr
Copy link
Contributor Author

ro0gr commented Nov 23, 2019

hm.. turns out, in click we don't even try to do anything with disabled inputs:

let isDisabledFormControl = isFormControl(element) && element.disabled;
if (!isDisabledFormControl) {
__click__(element, options);
}

I think it should throw. Will update.

@rwjblue
Copy link
Member

rwjblue commented Dec 4, 2019

I think it should throw. Will update.

👍

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to go once click has been updated to throw (along with tests).

Thanks for picking this up @ro0gr!

@ro0gr
Copy link
Contributor Author

ro0gr commented Dec 4, 2019

@rwjblue thanks for the feedback and sorry for letting it hang, going to come back to it this week.

Copy link
Member

rwjblue commented Dec 5, 2019

No problem, thanks for working on it!

@ro0gr
Copy link
Contributor Author

ro0gr commented Mar 9, 2020

Just added an error for click, and made sure all the other interactions fail if disabled element. rebased and squashed.

But a slight doubt appeared on my mind. I suspect it might be considered a breaking change, since we didn't fail on clicking disableds before.

I'm pretty sure there are some tests in the wild, like:

this.doSmth = () => {
  this.called = true
}

await render(hbs`<Something 
  @disabled={{true}}
  @onClick={{this.doSmth}}
/>`

await click('.Something');

assert.equal(called, false)

which I believe is totally valid with existing click implementation, but would fail with this proposed change. From the other hand, not throwing for disableds in {fill,type}-in should not be allowed, even it'd break some tests (imo).

@rwjblue please let me know, what do you think? Should I split the PR into 2, in order to merge {fill,type}-in stuff first, and let the the rest wait for the next major, or is it fine for you to go as is?

@ro0gr
Copy link
Contributor Author

ro0gr commented Mar 9, 2020

Should I split the PR into 2, in order to merge {fill,type}-in stuff first, and let the the rest wait for the next major, or is it fine for you to go as is?

extracted everything unrelated to fillIn and typeIn into another PR #778

@ro0gr ro0gr requested a review from rwjblue March 9, 2020 21:54
@ro0gr ro0gr changed the title Fail on edit non-focusable form controls Fail on edit disabled form controls Mar 29, 2020
@ro0gr ro0gr changed the title Fail on edit disabled form controls Respect "disabled" in "fillIn" and "typeIn" Apr 10, 2020
function isFocusableElement(
element: HTMLElement | SVGElement | Element
): element is FocusableElement {
function isFocusableElement(element: Element): element is FocusableElement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change the types here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was my attempt to simlify a bit. Both HTMLElement are SVGElement derrive from Element, so it does seem redundant to specify each.
Also, implementation wise it just checks if it's not an A tag!

await setupContext(context);
assert.rejects(
fillIn(`#${element.id}`, 'foo'),
new Error('Can not `fillIn` disabled [object HTMLInputElement]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have [object HTMLInputElement] in here?

Copy link
Contributor Author

@ro0gr ro0gr Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are passing an element instace, which is not focusable, into throw statement. Should prbably change it to use specifier(selector or Element) passed by user. Will update, thanks!


assert.rejects(
fillIn(element, 'foo'),
new Error("Can not `fillIn` disabled '[object HTMLInputElement]'."),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Turbo87 just improved error messages. See this one, and 1 assert above. Please let me know if it looks good for you.

@rwjblue rwjblue added the bug label Apr 20, 2020
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, I think it will need a rebase to fix some conflicts but we should be able to land and get it out in 2.0.0.

@ro0gr
Copy link
Contributor Author

ro0gr commented Apr 20, 2020

CI is failing due to some conflicts in ember-data/ember types. I suspect this was caused by this PR #784, which doesn't have travis results reported in the PR for some reason, so we've missed the breakage.

I think it's a good time to upgrade that types and ec-ts at once. Will look into it.

@rwjblue
Copy link
Member

rwjblue commented Apr 20, 2020

I rerolled the yarn.lock in #814 (since floating deps tests worked), mind trying again?

@rwjblue rwjblue merged commit fcbeba3 into emberjs:master Apr 21, 2020
@rwjblue rwjblue changed the title Respect "disabled" in "fillIn" and "typeIn" Error when attempting to fillIn/typeIn a disabled form control May 5, 2020
@rwjblue rwjblue added breaking and removed bug labels May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fillIn ignores the disabled property on inputs
3 participants