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

Setting containerTagName to null won't clear the container #761

Closed
zepumph opened this issue Mar 31, 2018 · 14 comments
Closed

Setting containerTagName to null won't clear the container #761

zepumph opened this issue Mar 31, 2018 · 14 comments

Comments

@zepumph
Copy link
Member

zepumph commented Mar 31, 2018

This happens when there are other siblings than just the primary sibling, basically because the default kicks in too strong. I want to discuss the desired functionality before diving in.

@zepumph
Copy link
Member Author

zepumph commented Apr 8, 2018

What should the functionality be? Other option remove pDOM content when set back to null, but I see the container potentially as a different beast. Potential options on behavior when containerTagName: null is set:

  1. No op, but we document it well.
  2. Assert if there are siblings, because that is broken code.
  3. Something clever and vague like automatically removing siblings, but documenting it well.
  4. Option 4: wildcard, any suggestions?

Marking for dev meeting.

@zepumph zepumph removed their assignment Apr 8, 2018
@jessegreenberg
Copy link
Contributor

jessegreenberg commented Apr 9, 2018

I like option 2. We have this assertion in insertContentElement:

assert && assert( accessiblePeer.containerParent, 'Cannot add sibling if there is no container element' );

Which will error if you do this:

    b.tagName = 'button';
    b.labelTagName = 'p';
    b.containerTagName = null;

But not if you do this:

    b.containerTagName = null;
    b.tagName = 'button';
    b.labelTagName = 'p';

Also, this won't error:

    var b = new Node( {
      tagName: 'button',
      labelTagName: 'p',
      containerTagName: null
    } );

because labelTagName happens to come after containerTagName in ACCESSIBILITY_OPTION_KEYS.

@jessegreenberg
Copy link
Contributor

Hmm, from #761 (comment),

    b.containerTagName = null;
    b.tagName = 'button';
    b.labelTagName = 'p';

is perfectly valid if default value for containerTagName is null. So I am not sure yet what the best option is.

@zepumph
Copy link
Member Author

zepumph commented Apr 10, 2018

I don't know what the word "valid" means here. Yes the above works, but the containerTagName is still added. This is because the labelTagName call adds in a parent automatically if conatiner is null.

Both of the following code snippets yield the same HTML. Please confirm and play in the playground.

    var b = new Node();
    b.containerTagName = null;
    b.tagName = 'button';
    b.labelTagName = 'p';
    var b = new Node( {
      tagName: 'button',
      labelTagName: 'p',
      containerTagName: null
    } );
<div class="accessibility">
  <div tabindex="-1" id="container-2-11">
    <p tabindex="-1" id="label-2-11"></p>
    <button id="2-11" tabindex="0"></button>
  </div>
</div>

@jessegreenberg
Copy link
Contributor

jessegreenberg commented Apr 10, 2018

Sorry, I was trying to say that they are effectively no-ops because the default value for containerTagName is null. It is only an error if you change the order so labelTagName is set before containerTagName.

@zepumph
Copy link
Member Author

zepumph commented Apr 10, 2018

I worry about it seeming clever and confusing. Here, an explicit call to nullify a tagName doesn't change the pDOM at all.

Maybe it will be good to describe this behavior in the containerTagName doc, "unlike other tagName setters, explicitly setting containerTagName to null will be overwritten if there are siblings in the peer."

@jessegreenberg
Copy link
Contributor

I agree it is a problem and think documentation may be the best way to go. What if we assert that containerTagName cannot be set to null, only allowing null as a default value on construction?

@zepumph
Copy link
Member Author

zepumph commented Apr 10, 2018

What about:

    var b = new Node( {
      tagName: 'button',
      labelTagName: 'p',
    } );

  b.labelTagName = null;
  console.log( b.containerTagName); // ---> 'DIV'
  b.containerTagName = null;
  console.log( b.containerTagName); // ---> null

Confirmed in playground. It seems like right now, it would be important to be able to clear that container after clearing the label. It is a bummer that you have to "cleanup" the container after you didn't even set it.

@jessegreenberg
Copy link
Contributor

jessegreenberg commented Apr 10, 2018

Totally agree.

It is a bummer that you have to "cleanup" the container after you didn't even set it.

Do you think it is worth throwing an error rather than creating a a default parent DOMElement when adding label/description siblings, so client always has to add the container?

EDIT: for clarity

@zepumph
Copy link
Member Author

zepumph commented Apr 10, 2018

No I don't think this is worth it. I think that makes things much more annoying to use, and that it isn't worth it to have to add this to every place where a sibling is declared (sorta like trading one gotcha for another).

Let's go down the documentation route, as devs will be looking at the doc for sibling/parent setters a lot as they learn how it works. We can get feedback from them as we go.

@jessegreenberg
Copy link
Contributor

OK, that sounds great to me.

@zepumph
Copy link
Member Author

zepumph commented Apr 11, 2018

Alright, @jessegreenberg please review and close if that's all (commit coming when my computer wakes up).

@jessegreenberg
Copy link
Contributor

This documentation was helpful, but I don't think it is accurate anymore after #715, since siblings no longer require a container tag name. I actually removed it. @zepumph can you please verify this is correct?

@zepumph
Copy link
Member Author

zepumph commented Apr 22, 2021

Good find! THanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants