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

FocusManager: error on refreshing container #17

Open
ItsAsbreuk opened this issue Apr 15, 2013 · 4 comments
Open

FocusManager: error on refreshing container #17

ItsAsbreuk opened this issue Apr 15, 2013 · 4 comments

Comments

@ItsAsbreuk
Copy link

Ryan,

I don't have time left to isolate the issue, so I hope it's reproducable...
I ran into this:

Gotta container with focusable-items, where I select one by focusManager.next().
Now, I refresh the container with new content (new focusable items)

I found out the console runs into continous erroring 'TypeError: node is null'
(node-core-debug.js line 347)

I think the error occurs because focusManager.next() calls nextItem.next(itemSelector);
Perhaps the definition inside YUI's internal nodelist is here defined and I ripped it away:

<div id='container'> <!-- has focusmanager plugged in -->
    <div id='insidecontainer'>
        <input type='text' value='1' /> <!-- focusable item -->
        <input type='text' value='2' /> <!-- focusable item -->
    </div>
</div>
insidecontainer.destroy(); // <-- removing this line will make the error disappear
insidecontainer.setHTML(newContent);

Thus, the error occurs when I manually call insidecontainer.destroy();
The error also does not appear when I focus by mouseclick. This made me think focusManager.next() had some code that interferred.

Regards,
Marco.

@ItsAsbreuk
Copy link
Author

Just updated the errordescription

@ItsAsbreuk
Copy link
Author

Hi Ryan,

I picked this up and traced the bug.
It happened when after an activeItemChange e.prevVal has a value, but the node is removed from the dom.

To resolve the issue, I made these changes:

_afterActiveItemChange: function (e) {
        var newVal  = e.newVal,
            prevVal = e.prevVal;

        if (prevVal && this.host.one('#'+prevVal._yuid)) {
            prevVal.set('tabIndex', -1);
        }

        if (newVal) {
            newVal.set('tabIndex', 0);

            if (this.get('focused')) {
                newVal.focus();
            }
        }
    },

Regards,
Marco

@rgrove
Copy link
Contributor

rgrove commented Nov 26, 2013

Thanks! I'll tackle this as soon as I get back to working on FocusManager.

@ItsAsbreuk
Copy link
Author

All right.

I think I was too ambigious in the proposed fix.
I am using this code now myself:

    _afterActiveItemChange: function (e) {
        var newVal  = e.newVal,
            prevVal = e.prevVal;

        if (Y.one(prevVal)) {
            prevVal.set('tabIndex', -1);
        }
        if (newVal) {
            newVal.set('tabIndex', 0);
            if (this.get('focused')) {
                newVal.focus();
            }
        }
    },

Marco

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