Correct way to open react-laag layers programatically
In Select we handle keyboard events which open the the layer via a workaround (effectively by simulating a click, see here):
if (triggerRef.current) {
//would probably be better to use useToggleLayer.open() here
//the ref click as workaround until this ticket is answered:
//https://github.com/everweij/react-laag/issues/37
triggerRef.current.click();
}
We should try to use the react-laag's API instead:
//EITHER:
toggleLayerProps.openFromRef(triggerRef);
//OR:
const {current} = triggerRef;
const clientRect = current.getBoundingClientRect();
toggleLayerProps.open({clientRect, target: current});
Current status: solution works for opening the layer. But the arrow keys are also bound to scrollbars in Storybook, and the layer doesn't reposition correctly when the component moves when solving things this way.
Edited by Mark Macdonald