Open Bug 1661507 Opened 4 years ago Updated 3 years ago

When manually removing all richlistitems from a richlistbox, the selectedItem is not null even though selectedIndex is -1

Categories

(Toolkit :: UI Widgets, defect, P5)

defect

Tracking

()

People

(Reporter: mbirghan, Unassigned)

Details

I am changing the certManager to use a richlist in the server tab. I noticed that if I remove the last element and rebuild the list the selectedIndex is -1 and the selectedItem is still the previously selected item. This is even though the richlist is empty.

Brian, do you know why the richlistbox doesn't appear to do any kind of tracking of its children? Seems like consumers just have to manually call methods if they remove selected items or something? I feel like I'm missing something here...

Component: General → XUL Widgets
Flags: needinfo?(bgrinstead)
Product: Core → Toolkit

(In reply to :Gijs (he/him) from comment #1)

Brian, do you know why the richlistbox doesn't appear to do any kind of tracking of its children? Seems like consumers just have to manually call methods if they remove selected items or something? I feel like I'm missing something here...

There's an appendItem method to append a child (https://searchfox.org/mozilla-central/rev/2b250967a66886398e5e798371484fd018d88a22/toolkit/content/widgets/richlistbox.js#376). But AFAICT there isn't a method to remove one. Weird this hasn't come up (at least that I'm aware of) in the 15 years the widget has been around.

I think this would work:

richlistbox.selectedIndex = -1
richlistitem.remove();

But more generally, what kind of change are you working on in the certificate manager? Is this referring to the tabs in about:certificate?

Flags: needinfo?(bgrinstead) → needinfo?(mbirghan)

If you open the certificate manager we have tabs for different types of certificates we use for different purposes. Right now most of them use nsITreeView to display the certificates in a list. Apparently we do not want to use nsITreeView anymore so I am replacing it with a richlist and some js code.

Also I achieved the expected behavior by using clearSelection().

Flags: needinfo?(mbirghan)

(In reply to Moritz Birghan [:mbirghan] from comment #3)

If you open the certificate manager we have tabs for different types of certificates we use for different purposes. Right now most of them use nsITreeView to display the certificates in a list. Apparently we do not want to use nsITreeView anymore so I am replacing it with a richlist and some js code.

Also I achieved the expected behavior by using clearSelection().

OK, got it. Btw if you do selectedIndex = -1 that will call clearSelection() and more for you: https://searchfox.org/mozilla-central/rev/eb9d5c97927aea75f0c8e38bbc5b5d288099e687/toolkit/content/widgets/richlistbox.js#194-196.

Summary: richlist selectedItem is not null even though selectedIndex is -1 and there is no item in the richlist → When manually removing all richlistitems from a richlistbox, the selectedItem is not null even though selectedIndex is -1
Priority: -- → P5
Severity: -- → S3
You need to log in before you can comment on or make changes to this bug.